Control Flow

Control flow in Laminar

Control flow basics

Adding if this then that logic in Laminar can be done by using Lam's in-built if statement syntax:

Conditional Execution Flow
.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

In the example above, we receive some JSON payload and decide whether we invoke a new workflow based on whether we have the correct initial conditions.

This control flow runs inside a workflow that was created to specifically handle the logic of whether or not to continue execution based on initial conditions.

Workflows can be created to specifically handle control flow and passing data to other workflows.

View another conditional Lam example
.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

In this example, we're either calling resolveThenExecute and invoking Workflow 60 to execute with an initial payload of . (this represents the entire value of the .input key) and resolving the request with a { "status": "OK" } or exiting our workflow entirely by using the exit keyword.

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

Last updated