Laminar
  • Laminar
  • Platform
    • Overview
    • Getting Started
    • Advanced
      • Configurations
      • HTTP Request Batching
      • Workflow Exit Points
      • Invoke Secondary Workflows
      • Managing Notifications
    • Best Practices
    • Keywords
      • lam.resolveThenExecute
      • lam.exit
      • lam.execute
      • lam.asyncExecute
      • lam.httpRequest
      • lam.httpRequests
  • Concepts
    • Workflows
      • Global Workflow Object
    • Flows
      • Flow Types
        • HTTP Request
        • Data Transformations
      • Flow Runs
      • Supported Languages
    • API Key
    • Configurations
    • API
      • Reference
        • Workspaces
          • Issues
          • Users
          • Invitations
            • Decline
            • Accept
            • Received
            • Created
          • Workflows
          • Flows
          • Auth credentials
          • Api keys
          • Api descriptions
        • Workflow
          • Execute
            • External
          • Flows
          • Executions
        • Users
        • Flows
          • Runs
          • Versions
          • Stats
          • Recent runs
          • Read
        • Configurations
          • Properties
          • Flow credentials
          • Workspace
        • Auth credentials
        • Api descriptions
        • Api keys
        • Transform
          • Test
        • Lami
          • Public
          • Direct
        • Auth
          • Signin
          • Register
          • Refresh
          • Me
          • Users
            • Password
    • Changelog
  • External Links
    • Book a Demo
    • Playground
    • Sign In
  • Specification
Powered by GitBook
On this page
  • Control flow basics
  • JavaScript Example
  • JQ Example
  • Another Control Flow Example
  • JavaScript Version
  • JQ Version
  • Laminar Keywords

Was this helpful?

  1. Platform
  2. Integration Design

Control Flow

Control flow in Laminar

Control flow basics

Adding if this then that logic in Laminar can be done using either JavaScript or JQ. Here are examples in both languages:

JavaScript Example

(payload) => {
  const { input } = payload;
  
  if ((input.activity_type === "route-destination-status" || 
       input.activity_type === "update-destinations") && 
      /skipped|failed|completed|loaded/.test(String(input.detailed_event)) &&
      input.order_id?.length > 0) {
    return {
      "lam.resolveThenExecute": {
        "lam.workflowId": 60,
        "lam.payload": input,
        "lam.result": { "status": "OK" }
      }
    };
  } else {
    return { "lam.exit": true };
  }
}

JQ Example

.input |
if ((.activity_type == "route-destination-status" or
     .activity_type == "update-destinations") and
    (.detailed_event? | tostring | test("skipped|failed|completed|loaded")) and
    (.order_id | length > 0))
then
{
  "lam.resolveThenExecute": {
    "lam.workflowId": 60,
    "lam.payload": .,
    "lam.result": { "status": "OK" }
  }
}
else 
    { "lam.exit": true } 
end

Another Control Flow Example

JavaScript Version

(payload) => {
  const results = payload.step_1.response.results;
  
  if (results.length === 0) {
    return { "lam.exit": true };
  } else if (results.length === 1) {
    return { 
      "order_ids": [Number(results[0].order_id)]
    };
  } else {
    return { "lam.exit": true };
  }
}

JQ Version

.step_1.response.results | 
if length == 0 then 
  { "lam.exit": true } 
elif length == 1 then 
  .[0] | { "order_ids": [(.order_id | tonumber)] }
else 
  { "lam.exit": true } 
end

Laminar Keywords

Keywords allow workflows to be executed conditionally from within flows, making it easier to support complex control flow logic within custom integrations.

Last updated 3 months ago

Was this helpful?