Difference between Rule editor in Core Components and Rule Editor in Foundation Components
The following table demonstrates the difference between the features available in the Rule Editor’s Core Components and the Rule Editor’s Foundation Components:
Understanding a rule
A rule is a combination of actions and conditions. In rule editor, actions include activities such as hide, show, enable, disable, or compute the value of an object in a form. Conditions are Boolean expressions that are evaluated by performing checks and operations on the state, value, or property of a form object. Actions are performed based on the value ( True
or False
) returned by evaluating a condition.
The rule editor provides a set of predefined rule types, such as When, Show, Hide, Enable, Disable, Set Value Of, and Validate to help you write rules. Each rule type lets you define conditions and actions in a rule. The document further explains each rule type in detail.
A rule typically follows one of the following constructs:
Condition-Action In this construct, a rule first defines a condition followed by an action to trigger. The construct is comparable to if-then statement in programming languages.
In rule editor, the When rule type enforces the condition-action construct.
Action-Condition In this construct, a rule first defines an action to trigger followed by conditions for evaluation. Another variation of this construct is action-condition-alternate action, which also defines an alternate action to trigger if the condition returns False.
The Show, Hide, Enable, Disable, Set Value Of, and Validate rule types in rule editor enforce the action-condition rule construct. By default, the alternate action for Show is Hide and for Enable is Disable, and the opposite way. You cannot change the default alternate action.
For more information about rule types available in the rule editor, see Available rule types in rule editor.
Guidelines for choosing a rule construct
While you can achieve most of the use cases by using any rule construct, here are some guidelines to choose one construct over another. For more information about the available rules in rule editor, see Available rule types in rule editor.
-
A typical rule of the thumb when creating a rule is to think about it in the context of the object on which you are writing a rule. Consider that you want to hide or show the field B based on the value a user specifies in the field A. In this case, you are evaluating a condition on field A, and based on the value it returns, you are triggering an action on field B.
Therefore, if you are writing a rule on field B (the object on which you are evaluating a condition), use the condition-action construct or the When rule type. Similarly, use the action-condition construct or Show or Hide rule type on field A.
-
At times, you must perform multiple actions based on one condition. In such cases, it is recommended to use the condition-action construct. In this construct, you can evaluate a condition once and specify multiple action statements.
For example, to hide fields B, C, and D based on the condition that checks for the value a user specifies in field A, write one rule with condition-action construct or When rule type on field A and specify actions to control the visibility of fields B, C, and D. Otherwise, you need three separate rules on fields B, C, and D, where each rule checks the condition and shows or hides the respective field. In this example, it is more efficient to write the When rule type on one object rather than Show or Hide rule type on three objects.
-
To trigger an action based on multiple conditions, it is recommended to use action-condition construct. For example, to show and hide field A by evaluating conditions on fields B, C, and D, use Show or Hide rule type on field A.
-
Use condition-action or action condition construct if the rule contains one action for one condition.
-
If a rule checks for a condition and performs an action immediately on providing a value in a field or exiting a field, it is recommended to write a rule with condition-action construct or the When rule type on the field on which the condition is evaluated.
-
The condition in the When rule is evaluated when a user changes the value of the object on which the When rule is applied. However, if you want the action to trigger when the value changes on the server side, like for prepopulating the value, it is recommended to write a When rule that triggers the action when the field is initialized.
-
When writing rules for drop-downs, radio buttons, or check boxes objects, the options or values of these form objects in the form are pre-populated in the rule editor.
Available operator types and events in rule editor
The rule editor provides the following logical operators and events using which you can create rules.
- Is Equal To
- Is Not Equal To
- Starts With
- Ends With
- Contains
- Is Empty
- Is Not Empty
- Has Selected: Returns true when the user selects a particular option for a checkbox, drop-down, radio button.
- Is Initialized (event): Returns true when a form object renders in the browser.
- Is Changed (event): Returns true when the user changes the entered value or selected option for a form object.
- Navigation(event): Returns true when the user clicks a navigation object. Navigation objects are used to move between panels.
- Step Completion(event): Returns true when a step of a rule completes.
- Successful Submission(event): Returns true on successful submission of data to a form data model.
- Error in Submission(event): Returns true on unsuccessful submission of data to a form data model.
Available rule types in rule editor
The rule editor provides a set of predefined rule types that you can use to write rules. Let’s look at each rule type in detail. For more information about writing rules in rule editor, see Write rules.
When
The When rule type follows the condition-action-alternate action rule construct, or sometimes, just the condition-action construct. In this rule type, you first specify a condition for evaluation followed by an action to trigger if the condition is satisfied ( True
). While using the When rule type, you can use multiple AND and OR operators to create nested expressions.
Using the When rule type, you can evaluate a condition on a form object and perform actions on one or more objects.
In plain words, a typical When rule is structured as follows:
When on Object A:
(Condition 1 AND Condition 2 OR Condition 3) is TRUE;
Then, do the following:
Action 2 on Object B;
AND
Action 3 on Object C;
_
When you have a multi-value component, such as radio buttons or list, while creating a rule for that component the options are automatically retrieved and made available to the rule creator. You need not type the option values again.
For example, a list has four options: Red, Blue, Green, and Yellow. While creating the rule, the options (radio buttons) are automatically retrieved and made available to the rule creator as following:
While writing a When rule, you can trigger the Clear Value Of action. Clear Value Of action clears the value of the specified object. Having Clear Value of as an option in the When statement lets you create complex conditions with multiple fields.
Hide Hides the specified object.
Show Shows the specified object.
Enable Enables the specified object.
Disable Disables the specified object.
Invoke service Invokes a service configured in a form data model (FDM). When you choose the Invoke Service operation, a field appears. On tapping the field, it displays all services configured in all form data model (FDM) on your Experience Manager instance. On choosing a Form Data Model (FDM) service, more fields appear where you can map form objects with input and output parameters for the specified service. See example rule for invoking Form Data Model services.
In addition to Form Data Model service, you can specify a direct WSDL URL to invoke a web service. However, a Form Data Model service has many benefits and the recommended approach to invoke a service.
For more information about configuring services in form data model (FDM), see Experience Manager Forms Data Integration.
Set value of Computes and sets the value of the specified object. You can set the object value to a string, the value of another object, the computed value using mathematical expression or function, the value of a property of an object, or the output value from a configured Form Data Model service. When you choose the web service option, it displays all services configured in all form data model (FDM) on your Experience Manager instance. On choosing a Form Data Model service, more fields appear where you can map form objects with input and output parameters for the specified service.
For more information about configuring services in form data model (FDM), see Experience Manager Forms Data Integration.
The Set Property rule type lets you set the value of a property of the specified object based on a condition action. You can set property to one of the following:
- visible (Boolean)
- dorExclusion (Boolean)
- chartType (String)
- title (String)
- enabled (Boolean)
- mandatory (Boolean)
- validationsDisabled (Boolean)
- validateExpMessage (String)
- value (Number, String, Date)
- items (List)
- valid (Boolean)
- errorMessage (String)
For example, it enables you to define rules to add check boxes dynamically to the Adaptive Form. You can use custom function, a form object, or an object property to define a rule.
To define a rule based on a custom function, select Function Output from the drop-down list, and drag-and-drop a custom function from the Functions tab. If the condition action is met, the number of checkboxes defined in the custom function are added to the Adaptive Form.
To define a rule based on a form object, select Form Object from the drop-down list, and drag-and-drop a form object from the Form Objects tab. If the condition action is met, the number of checkboxes defined in the form object are added to the Adaptive Form.
A Set Property rule based on an object property lets you add the number of checkboxes in an Adaptive Form based on another object property that is included in the Adaptive Form.
The following figure depicts an example of dynamically adding checkboxes based on the number of drop-down lists in the Adaptive Form:
Clear Value Of Clears the value of the specified object.
Set Focus Sets focus on the specified object.
Save Form Saves the form.
Submit Forms Submits the form.
Reset Form Resets the form.
Validate Form Validates the form.
Add Instance Adds an instance of the specified repeatable panel or table row.
Remove Instance Removes an instance of the specified repeatable panel or table row.
Navigate to Navigates to other Adaptive Forms, other assets such as images or document fragments, or an external URL.
Set Value of
The Set Value of rule type lets you set the value of a form object depending on whether the specified condition is satisfied or not. The value can be set to a value of another object, a literal string, a value derived from a mathematical expression or a function, a value of a property of another object, or the output of a Form Data Model service. Similarly, you can check for a condition on a component, string, property, or values derived from a function or mathematical expression.
The Set Value Of rule type is not available for all form objects, such as panels and toolbar buttons. A standard Set Value Of rule has the following structure:
Set value of Object A to:
(string ABC) OR
(object property X of Object C) OR
(value from a function) OR
(value from a mathematical expression) OR
(output value of a data model service or web service);
When (optional):
(Condition 1 AND Condition 2 AND Condition 3) is TRUE;
The following example takes the value in dependentid
field as input and sets the value of the Relation
field to the output of the Relation
argument of the getDependent
Form Data Model service.
Example of Set Value rule using Form Data Model service
Show
Using the Show rule type, you can write a rule to show or hide a form object based on whether a condition is satisfied or not. The Show rule type also triggers the Hide action in case the condition is not satisfied or returns False
.
A typical Show rule is structured as follows:
Show Object A;
When:
(Condition 1 OR Condition 2 OR Condition 3) is TRUE;
Else:
Hide Object A;
Hide
Similar to the Show rule type, you can use the Hide rule type to show or hide a form object based on whether a condition is satisfied or not. The Hide rule type also triggers the Show action in case the condition is not satisfied or returns False
.
A typical Hide rule is structured as follows:
Hide Object A;
When:
(Condition 1 AND Condition 2 AND Condition 3) is TRUE;
Else:
Show Object A;
Enable
The Enable rule type lets you enable or disable a form object based on whether a condition is satisfied or not. The Enable rule type also triggers the Disable action in case the condition is not satisfied or returns False
.
A typical Enable rule is structured as follows:
Enable Object A;
When:
(Condition 1 AND Condition 2 AND Condition 3) is TRUE;
Else:
Disable Object A;
Disable
Similar to the Enable rule type, the Disable rule type lets you enable or disable a form object based on whether a condition is satisfied or not. The Disable rule type also triggers the Enable action in case the condition is not satisfied or returns False
.
A typical Disable rule is structured as follows:
Disable Object A;
When:
(Condition 1 OR Condition 2 OR Condition 3) is TRUE;
Else:
Enable Object A;
Validate
The Validate rule type validates the value in a field using an expression. For example, you can write an expression to check that the text box for specifying name does not contain special characters or numbers.
A typical Validate rule is structured as follows:
Validate Object A;
Using:
(Expression 1 AND Expression 2 AND Expression 3) is TRUE;
Set Options Of
The Set Options Of rule type enables you to define rules to add check boxes dynamically to the Adaptive Form. You can use a Form Data Model (FDM) or a custom function to define the rule.
To define a rule based on a custom function, select Function Output from the drop-down list, and drag-and-drop a custom function from the Functions tab. The number of checkboxes defined in the custom function are added to the Adaptive Form.
To create a custom function, see custom functions in rule editor.
To define a rule based on a form data model (FDM):
- Select Service Output from the drop-down list.
- Select the data model object.
- Select a data model object property from the Display Value drop-down list. The number of checkboxes in the Adaptive Form is derived from the number of instances defined for that property in the database.
- Select a data model object property from the Save Value drop-down list.
Understanding the rule editor user interface
Rule editor provides a comprehensive yet simple user interface to write and manage rules. You can launch the rule editor user interface from within an Adaptive Form in authoring mode.
To launch the rule editor user interface:
-
Open an Adaptive Form in authoring mode.
-
Select the form object for which you want to write a rule, and in Component Toolbar select
Any existing rules on the selected form objects are listed in this view. For information about managing existing rules, see Manage rules.
-
Select Create to write a new rule. The visual editor of the rule editor user interface opens by default when you launch the rule editor the first time.
Let’s look at each component of the rule editor UI in detail.
A. Component-rule display
Displays the title of the Adaptive Form object through which you launched the rule editor and the rule type currently selected. In the above example, the rule editor is launched from an Adaptive Form object titled Salary and the rule type selected is When.
B. Form objects and functions
The pane on the left in the rule editor user interface includes two tabs — Forms Objects and Functions.
The Form Objects tab shows a hierarchical view of all objects contained in the Adaptive Form. It displays the title and type of the objects. When writing a rule, you can drag-drop form objects onto the rule editor. While creating or editing a rule when you drag-and-drop an object or function into a placeholder, the placeholder automatically takes the appropriate value type.
The form objects that have one or more valid rules applied are marked with a Green dot. If any of the rules applied to a form object are invalid, the form object is marked with a Yellow dot.
The Functions tab includes a set of built-in functions, such as Sum Of, Min Of, Max Of, Average Of, Number Of, and Validate Form. You can use these functions to compute values in repeatable panels and table rows and use them in action and condition statements when writing rules. You can, however, create custom functions too.
In the left tree of the form objects, you can select the form objects to display the rules applied to each of the objects. Not only you can navigate through the rules of the various form objects, you can also copy-paste rules between the form objects. For more information, see Copy-paste rules.