3. Logic

3.1. Variables

3.1.1. Creating Global Variables

  1. Go to “Variables” on the left hand side to create global variables.
  2. To create a new one click the “New Variable” button.
../_images/newvariable.png
  1. Choose a data type. These include boolean, date time, decimal, integer, secure string, string, or you can add a new data type.
../_images/variabletypes.png

3.1.1.1. Example Creation of a String Variable

  1. Select the type String
  2. Provide a display name and a description.
  3. Choose a scope for the variable and provide a value.
../_images/stringvariable.png

3.1.2. Creating a New Variable Type

  1. To create a new variable type go under “Variable Types” and click the “New Variable Type” button.
../_images/newvariabletype.png
  1. This creates a structure of the type table and asks for a display name and a description.
  2. Add new fields to the variable and click the “Submit” button to create the variable.
  3. This new variable type can now be used to create global variables.
../_images/newtypeinfo.png

3.1.2.1. Creating Local Variables

  1. To create a local variable click inside the workflow area and go to the properties section on the right.
  2. Scroll down until you reach the variables section.
  3. Click new variable.
../_images/localvariable.png
  1. Add info for new local variable
../_images/localvariableinfo.png

3.2. Condition Blocks

Condition blocks allow you to decide which path to take in a workflow.

3.2.1. Example Condition Block

This example sets a variable and then runs a python script based on what the value of the variable is.

  1. Add the action “Set Variables” followed by a condition block with two of the “Execute Python Script” actions inside.
../_images/setup.png
  1. Create a local variable for the workflow called “Condition” and make it a boolean and set it to True.
  2. Pass the “Set Variables” action the condition variable.
../_images/condition.png
  1. Click on the left condition branch and click the puzzle piece for the left operand and choose the “Condition” variable we created.
  2. Leave the operator as equals and set the right operand to True.
../_images/leftside.png
  1. In the left side “Execute Python Script” action add a simple script to print True.
../_images/true.png
  1. Click on the right condition branch and click the puzzle piece for the left operand and choose the “Condition” variable we created.
  2. Leave the operator as equals and set the right operand to False.
../_images/rightside.png
  1. In the right side “Execute Python Script” action add a simple script to print False.
../_images/false.png
  1. Validate and run the action.
  2. The resulting JSON will show the result printed was True as we had the local variable set to True.
../_images/conditionresult.png
  1. In the workflow you can see which path was taken as it will have a green square around it.
../_images/greenresult.png

3.3. For Each Blocks

The For Each block allows you to loop through data.

3.3.1. Example For Each Block

  1. Add a For Each block and add the “JSONPathQuery” action to it.
../_images/foreach.png
  1. Create a new variable type called Items and populate the table.
../_images/items.png
  1. Click on the For Each block and select the source array to be the items variable by clicking the puzzle piece.
../_images/sourcearray.png
  1. Click on the “JSONPathQuery” action and select the source JSON to query to be the first item in the table.
../_images/jsonquery.png
  1. Set the Query to “$”, the property name to “ITEM 1”, and the property type to “String”.
../_images/jsonvariables.png
  1. Validate the workflow and run it.
  2. After running, you can see that the For Each loop ran 3 times. You can drop down the iterations to see the result of each one.
../_images/iterations.png
  1. For the first iteration you can see the item it returned was “desk”.
../_images/resultjson.png

3.4. While Loop Blocks

A While block will loop until a certain condition is met.

3.4.1. Example While Loop Block

  1. Start by adding the “Set Variable” action and pass it a local variable called count that is set to zero.
../_images/count.png
  1. Add a While loop block and add the actions “Execute Python Script” and “Set Variable” to the condition branch.
../_images/whilesetup.png
  1. Add a script to the “Execute Python Script” action to add one to count.
  2. Set the script output to be called out.
../_images/outcount.png
  1. Set the “Set Variable” action to replace count with the result of the python script.
../_images/newcount.png
  1. Set the conditions in the condition branch to use the count variable, not equals, and ten.
../_images/whilecondition.png
  1. Run the workflow to see that it runs 10 times.
../_images/run10times.png

3.5. Parallel Blocks

Parallel blocks allow you to run two actions concurrently and wait until they both complete before doing the next action.

3.5.1. Example Parallel Block

  1. Start by adding “Create VPC” and “Create Subnet in VPC”.
../_images/startparallel.png
  1. Add a parallel block and put both actions in it.
  2. Add the “Execute Python Script” after the parallel block.
../_images/parallelblock.png
  1. When the workflow is run it will run both “Create VPC” and “Create Subnet in VPC” and wait till they are both done before running “Execute Python Script”.
  2. To add more actions to a parallel block click the plus sign in the top right corner of the block.
../_images/newblock.png