LCS - Conditionals in Actions
- Create An Action
- Create The Start Variables
- Create The Condition Action Step
- Create The Condition Paths
- Create The Filter Rule
- Add An Action To The Conditional Paths
A conditional action step is used to create the logic which determines which of two or more options in an action path will be followed. The Action builder creates a drag-and-drop interface with a series of configuration steps to make this logic happen inside the platform.
Any piece of data contained in a data model property, passed into the action through a variable, or calculated in the action itself can be used in the decision-making process of the conditional action step. The only critical parts about this data element are that it is contained in a variable, and that you can test the value in the variable using a condition like greater than, less than, equal or not equal to some other value. The second value can also be a variable, or it can be a constant like today's date or the number 42.
In this example, you will be building a long-range weather prediction application based on whether a groundhog sees his shadow or not.
Create An Action
1. If you are not building a loop inside of an auto-generated action (one created by the platform as a result of your dragging and dropping web components onto the canvas) you can create a new action using the button in the upper right of the Action panel on the left side of the interface:
2. Your empty action will be created after you give it a useful name in the action creation dialog:
Create The Start Variables
For the purposes of this tutorial, there will be two variables in the Start action step. One will be an input variable - the observation checkbox SeeShadow that will reflect one of two possible conditions - that the groundhog sees his shadow or he does not. The other variable will be a daily record from the LongTermForecast model named GroundhogDay for today's long-term prediction, which for the purposes of this tutorial will be updated on February 2 of each year.
- Click on the Start action step to open the configuration panel at the right.
- In the Input Variables tab, click on the Add button, then add the details for the input checkbox variable called SeeShadow. The True or False value for this variable will be passed to the action in the calling step from the web form.
- Be sure to click on the Save button in the lower-right corner of the configuration panel to save your changes.
The completed configuration is shown in this screenshot:
-
In the Action variables tab, click on the Add, then configure a record variable to retrieve today's data from the LongRangeForecast data model. That completed configuration is shown in this screenshot:
Create The Condition Action Step
- Drag the Condition action step from the left pane onto the spinner between the Start and Finish action steps, dropping it on the spinner that appears between those two steps while you are dragging it onto the canvas.
- Your action path should look like the following:
Create The Condition Paths
- Click on the Condition action step to open the Condition configuration panel at the right of the screen.
- Rename the Condition by clicking on the placeholder title at the top of the configuration panel. Change the name to something appropriate for the conditional test, like "Groundhog Sees Shadow?"
- Next, update the Condition action step by renaming Path 1 to "Yes - Six More Weeks Of Winter". This will be the path that is followed if the checkbox is true, or checked. Note that renaming this path is not required, but it is helpful to you and the next person who is trying to follow the logic of your configuration.
- Rename the last path "No - Early Spring" which will be the one followed if the checkbox is false or unchecked.
- There are two paths in this simple example, one for true, the other false. These are the only two states a checkbox field can be in. The number of paths in your business process may have two or more possibilities, in which case you should add one path for each possibility plus a final path to handle any set of circumstances that fall outside of the expected states.
- If your business case does require more than two paths, you can add another path to the branching logic using the Add Path button. Note that each of your paths should also have a unique and mutually exclusive filter rule so that it is not possible for there to be more than one correct path through the action. If by mistake multiple paths are possible, the first path that evaluates to true from top to bottom in the list will be followed.
Create The Filter Rule
- Click on the Add Filter Rule under Yes - Six More Weeks Of Winter and add a filter to determine if the SeeShadow checkbox was checked. This is a simple check, but you can add more rules or a more complex evaluation as your business requirements suggest. These filter rules are the second critical component of Condition configuration, after creating the paths themselves.
- You will need to complete a filter rule for each of your paths except the last path, which will handle anything that isn't logically covered by the possibilities that come before it in the condition paths.
- The completed configuration for this is shown here:
4. Make sure you save all of your changes, then click on the X in the upper right corner to close the configuration pane.
Add An Action To The Conditional Paths
- After determining how many paths there are in your logic, you will need to specify what happens on each of those paths, including what happens on the final path, if anything, when none of the other conditions are met.
- Drag an Update action to each path of the Condition action step. In this example, the Prediction property in the record will be updated to one of two specifc values - "Six more weeks of winter" or "Early spring."
- In the Update action for the Six more weeks of winter path, set the Prediction property of the GroundhogDay record to the value "Six More Weeks of Winter".
- In the Update action for the Early spring path, set the Prediction property of the GroundhogDay record to the value "Early Spring".
- Save all of your changes, then test your action to make sure it works as intended.
- Your completed configuration for the Update action in the Six More Weeks Of Winter path will look like the following:
The completed action path should look like the following: