Conditions
This screen stipulates the if conditions of the Rules, in other words when the Rule will execute. Select the Simple Comparison, Validation or Custom Condition required to display the Rule Definition on the canvas. Items that are in green are configured, items that are in green with a dotted line still need to be configured, and items in grey cannot be configured until something else has been set. Configure the rule by replacing the green with the relevant setting.The conditions available are described in the below table:
Type | Template | Used For |
---|---|---|
Simple Comparisons | A control contains a value | Ensuring a field is not blank |
Simple Comparisons | A control contains a specific value | Firing a rule only when a specific field has a specific value |
Simple Comparisons | A control does not contain a value | Firing a rule when a field is blank |
Simple Comparisons | A control does not contain a specific value | Firing a rule if a field is not a specific value, such as when Region does not equal USA, then Load Territories |
Simple Comparisons | A control on a View contains a value | Ensuring a field is not blank on a View |
Simple Comparisons | A control on a View does not contain a value | Firing a rule when a field is blank on a View |
Simple Comparisons | A control on a View contains a specific value | Ensuring a field contains a specific value on a View |
Simple Comparisons | A control on a View does not contain a specific value | Firing a rule when a field is not a specific value on a View |
Simple Comparisons | A control on a subview contains a value | Ensuring a field is not blank on a subview |
Simple Comparisons | A control on a subview does not contain a value | Firing a rule when a field is blank on a subview |
Simple Comparisons | A control on a subview contains a specific value | Firing a rule only when a specific field has a specific value on a subview |
Simple Comparisons | A control on a subview does not contain a specific value | Firing a rule if a field on a subview is not a specific value, such as when Region does not equal USA, then Load Territories |
Simple Comparisons | A control on a View on a subform contains a value | Ensuring a field is not blank on a View on a subform |
Simple Comparisons | A control on a View on a subform does not contain a value | Firing a rule when a field is blank on a View on a subform |
Simple Comparisons | A control on a View on a subform contains a specific value | Firing a rule only when a specific field has a specific value on a View on a subform |
Simple Comparisons | A control on a View on a subform does not contain a specific value | Firing a rule if a field on a View on a subform is not a specific value, such as when Region does not equal USA, then Load Territories |
Simple Comparisons | A control on a subform contains a value | Ensuring a field is not blank on a subform |
Simple Comparisons | A control on a subform does not contain a value | Firing a rule when a field is blank on a subform |
Simple Comparisons | A control on a subform contains a specific value | Firing a rule only when a specific field has a specific value on a subform |
Simple Comparisons | A control on a subform does not contain a specific value | Firing a rule if a field on a subform is not a specific value, such as when Region does not equal USA, then Load Territories |
Simple Comparisons | A control on this Form contains a value | Ensuring a field is not blank on the current Form |
Simple Comparisons | A control on this Form does not contain a value | Firing a rule when a field is blank on the current Form |
Simple Comparisons | A control on this Form contains a specific value | Firing a rule only when a specific field has a specific value on the current Form |
Simple Comparisons | A control on this Form does not contain a specific value | Firing a rule if a field on the current Form is not a specific value, such as when Region does not equal USA, then Load Territories |
Parameter Conditions | A Form parameter has been specified |
Ensuring a parameter on the Form is not blank |
Parameter Conditions | A Form parameter has not been specified |
Firing a rule when a parameter on the Form is blank |
Parameter Conditions | A Form parameter has a specific value |
Firing a rule only when a parameter has a specific value on a Form |
Parameter Conditions | A Form parameter does not have a specific value |
Firing a rule if a parameter on a Form is not a specific value |
Parameter Conditions | A subform parameter has been specified |
Ensuring a parameter on the subform is not blank |
Parameter Conditions | A subform parameter has not been specified |
Firing a rule when a parameter on the subform is blank |
Parameter Conditions | A subform parameter has a specific value |
Firing a rule only when a parameter has a specific value on a subform |
Parameter Conditions | A subform parameter does not have a specific value |
Firing a rule if a parameter on a subform is not a specific value |
Parameter Conditions | A subview parameter has been specified |
Ensuring a parameter on the subview is not blank |
Parameter Conditions | A subview parameter has not been specified |
Firing a rule when a parameter on the subview is blank |
Parameter Conditions | A subview parameter has a specific value |
Firing a rule only when a parameter has a specific value on a subview |
Parameter Conditions | A subview parameter does not have a specific value |
Firing a rule if a parameter on a subview is not a specific value |
Parameter Conditions | A View parameter has been specified |
Ensuring a parameter on the View is not blank |
Parameter Conditions | A View parameter has not been specified |
Firing a rule when a parameter on the View is blank |
Parameter Conditions | A View parameter has a specific value |
Firing a rule only when a parameter has a specific value on a View |
Parameter Conditions | A View parameter does not have a specific value |
Firing a rule if a parameter on a View is not a specific value |
Parameter Conditions | A View parameter on a subform has not been specified |
Firing a rule when a View parameter on the subform is blank |
Parameter Conditions | A View parameter on a subform has been specified |
Ensuring a View parameter on the subform is not blank |
Parameter Conditions | A View parameter on a subform has a specific value |
Firing a rule only when a View parameter has a specific value on a subform |
Parameter Conditions | A View parameter on a subform does not have a specific value |
Firing a rule if a View parameter on a subform is not a specific value |
Validation Condition | The Form passes validation | To ensure that all controls pass validation before calling a method such as create or save. |
Custom Conditions | An advanced condition is true |
Advanced conditions using SmartForms data and comparison operators such as:
|
Logical Conditions | Else |
Use in conjunction with Custom/Advanced Conditions |
Error Handling | Error occurred |
See the Error handling topic for more details |
Workflow Condition | a Workflow activity is specified |
Ensuring a workflow activity is not blank |
Workflow Condition | a Workflow activity on a subview is specified |
Ensuring a workflow activity on a subview is not blank |
Workflow Condition | a Workflow activity on a subform is specified |
Ensuring a workflow activity on a subform is not blank |
Workflow Condition | a Workflow activity on a View on a subform is specified |
Ensuring a workflow activity on a View on a subform is not blank |
For-Each Looping | For each item in a List View |
Execute a block of actions for each item in a List View that meets a specified condition. |
For-Each Looping | For each item in a subview |
Execute a block of actions for each item in a subview that meets a specified condition. |
For-Each Looping | For each item in a List View on a subform |
Execute a block of actions for each item in a List View on a subform that meets a specified condition. |
For-Each Looping | For each item in a list control on a View |
Execute a block of actions for each item in a list control on a View that meets a specified condition. |
For-Each Looping | For each item in a list control on a subview |
Execute a block of actions for each item in a list control on a subview that meets a specified condition. |
For-Each Looping | For each item in a list control on a View in a subform |
Execute a block of actions for each item in a list control on a View in a subform that meets a specified condition. |
Mode | If the View is in a certain mode |
Firing a rule if a View is in a certain mode. Mode could be normal or offline. |
Mode | If a View on the Form is in a certain mode |
Firing a rule if a View on the Form is in a certain mode. Mode could be normal or offline. |
Mode | If the Form is in a certain mode |
Firing a rule if a Form is in a certain mode. Mode could be normal or offline. |
Mode | If the subview is in a certain mode |
Firing a rule if a subview is in a certain mode. Mode could be normal or offline. |
Mode | If the subform is in a certain mode |
Firing a rule if a subform is in a certain mode. Mode could be normal or offline. |
Mode | If the View on a subform is in a certain mode |
Firing a rule if a View on a subform is in a certain mode. Mode could be normal or offline. |
When using the Condition An advanced condition is true, a dialog opens where Advanced Conditions can be configured. The same principles are applied here as in the Expression Builder. SmartForms data can be used together with comparison operators such as:
- Equals or Not Equals
- Greater Than or Less Than
- Greater Than Equals or Less Than Equals
- Contains, Starts With or Ends With
- Is Empty or Is Not Empty
Brackets can be added by clicking on the white spaces between each condition to group conditions as shown below.
If no brackets are applied, OR and AND operators have the same precedence. By applying brackets, the order of execution can be specified.
The following is an example of an Expression tree:
which evaluates to the following:
(((1 OR 2) AND 2) AND 4)
In this example, the OR will execute first and then the two AND operators.
Click here for more information on Parameter rules
The option to disable validation on hidden, disabled or read-only controls, Views and tabs exists. The option is selected by default for all new controls, Views and tabs created that are hidden, disabled or read-only. Controls, Views and tabs that were hidden, disabled or read-only in versions prior to K2 smartforms 1.0.2, will be deselected and the option will have to be checked manually should validation not be performed on these.
Controls, Views and tabs can be validated by using the if the View/Form passes validation condition in the Rule Designer.
Clicking on configure next to the condition will open the validation screen. The option can be selected to disable the validation on hidden, disabled or read-only controls, Views and tabs. This will result in all other controls selected to be validated except the hidden, disabled and read-only controls, Views and tabs.
Required - Requires a value for the validation to succeed. A required control will automatically be validated against the data type of the control.
Validate - Validates the value of the control against the data type of the control, for example does a control of type Number contain a valid number.
Do not validate, hidden, disabled and read-only controls, Views or tabs - All controls belonging to these categories will be ignored when validation is performed, i.e. no validation will be done.
When using a Form with Views, the controls on those can also be selected to be disabled for validation.
Views and tabs can be configured to be hidden and disabled by using Actions in the Rule Designer or the Views can be hidden or disabled by changing the Properties of the View in the Form Designer.
The option to not validate hidden, disabled or read-only controls, Views and tabs will also be applied to controls and Views that are dynamically changed to disabled or read-only in runtime. For example if a control is enabled and is subsequently changed in runtime to be disabled, this option will be applied to that control if the validation is done after the control is changed to disabled.
The For-each Looping conditions below are available for use on List Views and list controls. These conditions can be used together with other If conditions or on its own. The conditions allow the user to perform actions for all items that meet a specified condition.
Permutations:- Create a Student 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.
- Configure the method as follows:
- Finish the View.
- Run the Students Form.
- Capture information into the Students tab and click on Save.
- Click on the Registered tab and refresh the View. Note that only the user with a Passed value of True has been created in the Registered SmartObject.
To only save new rows created, use the Added permutation. So only rows that were added to the list will be evaluated and actioned.
- 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.
- Configure the rule as follows:
- 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.
The same principle applies when using the For-Each Looping conditions on a list control. It is however advised to think logically about a list 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 would work.
- For-each conditions cannot be applied to inherited rules.
- For-each conditions cannot be used 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.
- For nesting scenarios, the execute another rule action should be used.
The Mode conditions allow the user to build rules around Views and Forms for when they are defined as Offline. K2 Mobile makes use of the behavior associated with the mode parameter set to Offline, and so can be used as the front-end for Forms. All other platforms will execute within Normal mode.
One example is where the device is offline when opening the Form in K2 Mobile, a message can be sent to inform the user of the offline status.
Permutations:
Normal - Forms and Views have full functionality and require a connection to the server.
Offline - Forms and Views have limited functionality and work without a connection to the server.
Advanced conditions can also be created to check the mode status before executing an action by dragging the Mode from the System Values of the Context Browser.
- Create a SmartObject.
- Create an Item View of the SmartObject containing a Create button.
- Edit the When Create Button is Clicked rule and add the following condition and action:
- Configure the message as follows and drag the Mode from the Context Browser into the mail as shown below :
- Save the rule and the View.
- Add the View to a Form.
- Set the Offline Availability setting in the Advanced section of the Form properties. This will enable the offline mode condition to execute when the Form is offline.
- Set the Application Form setting in the Advanced section of the Form properties. This makes the Form available in the Forms folder of the K2 Mobile app.
- Save the Form.
- Move the Form to the System > Application Forms folder so that it is available as an application form in the K2 Mobile app.
- Check in the View and Form.
- Open the Form from the K2 Mobile app.
- Change the settings in K2 Mobile to be offline.
- Capture some data and click the Create button.
- The message is displayed.
- To test the rules before using it on the device, run the View and insert ?_mode=offline into the query string (url) of the page as shown below:
- The mode is determined by the mobile device's status when the Form is opened. For example if the mobile device is offline, the mode will be reflected as offline and Views and Forms will in turn be offline. If the mobile device's status change to offline while a user is capturing data for example, the information will be saved in the Outbox and submitted when the mobile is online again.
- The mode should not be confused with the Offline Availability setting of the Form properties. The Offline Availability setting in the Form properties needs to be set to enable the offline mode conditions to work for K2 Mobile.
- If a Form contains a View and the Form is offline, the View will inherit the offline setting. The same principle is applicable to subviews and subforms.
- When creating rules around the offline mode feature, it is important to note that only client side actions will execute when the mobile device is offline. Server side actions will NOT be available while the mobile device is offline.
- It may be a good idea to perform offline mode conditions and actions in a batch when the View/Form initializes to inform the user at that point already if the device is offline.