On Delete
Rules and examples |
---|
|
Rules are client-side scripts (no-code business logic) that are executed when a user of the mobile app interacts with the app. The On Delete rules are executed when an existing instance of a repeatable group is deleted. Rules are managed using the rules editor.
On Delete rules are available for the following components: Questionnaires
Repeatable group
On Delete rules are only applicable to Repeatable groups. Questions are usually organized into groups. Instead of creating a questionnaire with the same set of questions multiple times, repeatable question groups offer the ability to repeat the grouped questions either arbitrarily (not known beforehand) or precisely specified number of times. Group can be set as repeatable in questionnaire properties.
Repeatable question groups are useful in cases such as:
- User needs to enter multiple addresses
- User needs to enter data about more than one result of the same issue (checking 10 identical parts of a machine)
- User needs to enter multiple pictures of the same object
Example: Repeatable group counter
Each instance of the repeatable group in the questionnaire is counted.
Create a shared variable (integer) repeatableCounter. If the questionnaire is new, assign 1 to the repeatableCounter.
Note | The default value in the variable is 0. When the questionnaire is loaded, one instance of the repeatable group already exists. Therefore, we have to set the value to 1. This has to be set in the root question On Load. If we set the On Load rule for a repeatable group, the value will be set to 1 each time a new instance is created. |
For the repeatable group, set the following On Repeat rule: If a new instance of a repeatable group is created, repeatableCounter +1.
For the repeatable group, set the following On Delete rule: If an instance of a repeatable group is deleted, repeatableCounter -1.
Create a new question group (Conclusion) and add a Whole Number component (Inspected components). This is where we assign the result of the counter. We set the question group as non-visible to display the result only in the report.
Set up a following On Save rule. If repeatableCounter contains data, assign its value to the question Inspected components.
Report: