Configure For Each Looping Conditions
You can use the For-Each Looping conditions on list views and list controls to perform actions for all items that meet a specified condition, such as to remove selected records from a list or execute a create method for all items when a condition is true. Use looping conditions with other If conditions or on their own.
Example 1: Rule with a For each item in a List View condition and the Selected item state to remove multiple selected rows from a list.
Example 2: Rule with an advanced condition uses the if an advanced condition is true condition to create records based on the condition.
When you configure the For-Each Looping conditions, you can use one of the following item state options:
- Added - Executes an action for all new rows in the list
- All - Executes an action for all rows in the list
- Changed - Executes an action for changed rows
- Removed - Executes an action for deleted rows
- Selected - Executes an action for selected rows
- Unchanged - Executes an action for unchanged rows
- Unselected - Executes an action for unselected rows
The sections below illustrate two methods for configuring For-Each Looping conditions. See the Considerations for more information and other considerations.
The example below shows how to use a For-Each Looping condition to action selected records in an editable list view, for example deleting all selected records. The images below show how you can select multiple records and click Delete to remove them all, and what the rule looks like in design time.
Follow the steps below to configure the rule shown above.
- Edit the rule you want to add the selected delete to such as When Delete ToolBar Button is Clicked.
- Select the Conditions tab, click the For each item in a List View condition in the For-Each Looping section, and then select the Selected item state as shown below.
- Hover over the rule condition and click the icon as shown below to move the statement up.
- The rule removes all selected rows when the Delete Toolbar Button is clicked.
The example below shows how to use a For-Each Looping condition and an advanced condition to create records where an advanced condition is true. In the image below, the existing rule actions execute on the Students SmartObject when the Save ToolBar Button is Clicked. In addition to those actions, you want to create records using the Registered SmartObject when a specific condition is true, as shown here in the red block:
Follow the steps below to configure the rule shown above.
- Edit the rule you want to add the condition to such as When Save ToolBar Button is Clicked.
- Select the Conditions tab, click the For each item in a List View condition in the For-Each Looping section, and then select the All item state as shown below.
- Click the an advanced condition is true rule condition in the Custom Conditions section, and then click the dotted line to configure the condition.
- Click Add and specify conditions containing a value on the left, an operator, and a value on the right. You can type a value or use the Context Browser to drag and drop a value. In this case, you need to create a new record for each student who passes their current class. See Configure Advanced Filter Conditions for more information about advanced conditions.
Click OK to save the configuration.
- Select the Actions tab and select Execute a method on the View in the SmartObject Interaction section. Select a SmartObject where you want to create the data, choose Create for the method to execute, and click configure to configure the method.
- Configure the Input Mappings by typing values or use the Context Browser to drag and drop values. These values are used to create records in the SmartObject you selected. Click Finish to save the configuration.
- The statements you added to the rule create new records in the Registered SmartObject for all rows with a Passed value of true.
- You can select multiple records in a list view using the keyboard functionality (Ctrl+Click, Shift+Click or Ctrl+A)
- When you use a For-Each Looping condition on a list view with paging enabled, the condition only iterates on the first page of the list view. If you need to loop through all items in a list view, do not enable paging.
- When you use a For-Each Looping condition, you can only use one If condition or a block of actions as shown in the examples below. You can not use more than one If condition in a For-Each Looping condition statement.
- If you want to create nested scenarios such as using an If statement inside another If statement, or a For-Each Looping condition within another For-Each Looping condition, you can use the execute another rule action as shown in these images:
- When you use these conditions with a list control, think logically about the control before selecting the item state. For example, don’t use the Checked item state on a Picker control because you can only select items using the control. Use the Selected item state instead.