Documentation

1.2.1 Conditional Code

Conditional Code

Conditional Code is a JavaScript expression that determines if an Action will be executed or skipped. You can base the expression on things like a previous action’s status, its final result payload, the Pipeline’s current configuration, or a function or variable on the Code page.

Unlike parameters, Conditional Code must be a valid boolean JavaScript expression – for example, evaluating to either true or false. The simplest case is the one-word code false, which would cause the Action to never execute. If you leave it blank the Action will always execute.

Example 1: Execute the Action only if a previous Action in the Pipeline was skipped

Here’s how to conditionally trigger an Action if a previous Action in the Pipeline was skipped.

 actions.attachNewVolume.status=='skipped'

If the Action with ID “attachNewVolume” was skipped, this evaluates to true, so this Action will execute.

Example 2: Execute an Action based on an earlier Action’s final result

In this example, we have an action that will start an Amazon EC2 instance only if it is not already running. The previous action ID is “getServerStatus”, and the final result is a JSON document that comes from the “describeInstances” method of the Amazon EC2 plugin.

 (actions.getServerStatus.result.describeInstances.Reservations[0].Instances[0].State.Name != "running")

Pre and Post-Execution Functions

Pre and Post-Execution Functions are simply code functions that execute immediately before and after the Action, respectively. You can use this for nearly anything – gathering information for Conditional Code, gathering or assembling Action’s parameters, triggering external systems in preparation for the Action, or publishing the Action’s results to external systems. These functions are also very useful to execute logical loops and stash results in variables along the way.

Unlike conditional code, these are not boolean JavaScript expressions, but typically functions that accept and return no parameters. However, any variables they create or set do remain in context for the Action to use.

Action Coordination

Action Coordination determines if an Action runs only once or potentially many times. It allows you to control when the Action is executed in relation to Actions that come before it.

You will see this in the Advanced tab of an Action’s edit panel only when more than one flow is connected to the front end of the Action, for example when Action is looping back upon itself. There are up to three options for this:

  • Wait for all – the Action will run only when every inbound flow has successfully arrived. This is not an option for Actions that start loops.
  • Run once for first – the Action will run only once, when first triggered by any upstream Action.
  • Run for each in link – the Action will run every time any upstream Action triggers it, or a loop re-enters it.

The Action Coordination can be used in combination with Conditional Code, for example skipping an execution whenever the code evaluates to false. However, if the Action Coordination does NOT run the action, then the Conditional Code has no effect at all. A loop, for example, cannot work if we have configured Action Coordination to “Run once for first”.

Page Contents