How To: Use For Each Looping Conditions
You can use the For-each Looping conditions on List views and list controls. Use them with other If conditions or on its own. The conditions allow you to perform actions for all items that meet a specified condition.
Use the following permutations with the For Each Looping conditions:
How to create records for all items that meet a specific condition
The example below shows how to use the for each looping condition and an advanced condition to create records where the advanced condition is true.
- Create a Students SmartObject for example containing the following properties:
- Create a Registered SmartObject containing the following properties:
- Generate an Editable List view from the Students SmartObject and a List view from the Registered SmartObject.
- Select both views and auto-generate a Students form.
- Edit the Students Editable List view and navigate to the rules.
- Edit the When Save ToolBar Button is Clicked rule and select the Conditions tab.
- Scroll down to the For-each Looping section and select the For each item in a List View condition.
- Select the All permutation.
- Select the condition if an advanced condition is true and configure it as follows:
- Go to the Actions tab and select Execute a SmartObject method. Select the Registered SmartObject and the Create method.
This means that only records with a Passed value of true is created in the Registered SmartObject.
- Configure the method as follows:
- Finish the view.
- Run the Students form.
- Capture information into the Students tab and click on Save. Ensure you create a record where the student has passed.
- Click on the Registered tab and refresh the view. Note that only the record with a Passed value of true is created in the SmartObject.
To only save new rows created, use the Added permutation. So only rows that are added to the list are evaluated and actioned.
How to enable multiple selection of records
The example below shows how to use a for each looping condition to enable a multiple selection of records at runtime.
- Create the same scenario as above.
- Edit the Students Editable List view.
- Navigate to the rules and edit the When Delete ToolBar Button is Clicked rule.
- Select the For each item in a List View condition and the Selected permutation, then move the condition above the action as shown below.
- Finish the rule.
- Finish the view.
- Run the Students form.
- Select multiple records using the keyboard functionality (Ctrl+Click, Shift+Click or Ctrl+A)
- Click the Delete button. Note how all the records selected are removed from the list.
Considerations
- You cannot apply these conditions to inherited rules.
- You cannot use these conditions directly using a SmartObject; it must be bound to a view or control.
- The handler can only contain one condition or a block of actions.
- If you want to create nesting scenarios, you must use the execute another rule action.
- When you use these conditions with a list control, it is advised to think logically about the control before selecting the permutation, for example it won't make visual sense to use the Checked permutation on a Picker control, even though the functionality works.