Most of the interactive behaviours exhibited by interactive forms are achieved using rules.
There are two types of rules:
- Page rules - Each page of the form has a set of rules which pertain to the content on that page, or to the form's records. The rules are evaluated when the page is first displayed, then whenever a control's value is changed, and finally when the user navigates to the next page.
- Form rules - A separate set of rules can be evaluated when the user clicks the Finish button on the form.
In broad terms, rules consist of a set of conditions which can examine the values of controls and records on the form and then, depending on the result, perform a series of actions that affect the remainder of the form.
Each rule has a Comments field, which can be used to further describe its purpose/meaning. In the absence of a comment, the rule will be described according to its content.
Rules are composed using an editor. You select the type of rule you wish to create, add it to the list and then begin assigning conditions, actions and values to it. Any problems with the rule (such as missing details) will be displayed when you save your changes. The editor is structured such that the rule can be read from left-to-right, top-to-bottom.
Conditions
Conditions allow rules to make decisions and perform a different set of actions depending on their outcome. A rule can have multiple conditions, combined using "and"/"or" logic. You can also negate ("not") any condition, reversing its result (e.g. "exists" becomes "does not exist", "equals" becomes "not equal to", etc). Conditions are evaluated in the order in which they appear, which may be significant to the outcome.
Most conditions examine one or more values (are also used in actions, see below). A value can be one of the following:
Static value - The value is typed into the rule editor and does not change.
Control - The value is taken from a
control on the page. The value can be changed by a rule.
Record - The value is taken from a property on a
record*, or the record as a whole†. The value can be changed by a rule.
ContactsLaw item - The value refers to a specific item in the ContactsLaw database; for example, a contact, workgroup or financial transaction. Typically used when setting the value of a property that does not accept a static value.
Formula - The value is built using a
formula expressed in terms of variables containing other values. The value cannot be changed by a rule unless '
dynamic evaluation' is enabled.
Lookup - The value is obtained by scanning a particular column in a lookup
table, and then returning the value from a different column on the matched row. The value cannot be changed by a rule.
Current item - The value is obtained from the current item in a For-Each rule. The value can be changed by the rule (unless referring to the item's name or position in the list).
* - In cases where the property is a workgroup field containing a table, you can select a specific column and aggregation function (e.g. Sum, Count, Average) from which the value is obtained.
† - Referring to the record as a whole allows you to load an existing contact, file or document by its unique identifier.
The following types of conditions can be used:
Comparison - Compares two values (from above) and determines whether they are equal, greater/less than, etc.
Contact check - Performs a range of checks on a
contact record (e.g. has an e-mail address, meets client criteria, etc).
Contact type - Determines whether a contact is of a certain type (e.g. individual or entity).
Empty/non-empty - Determines whether a value is empty. Provided as a short-hand version of the comparison condition.
Exists/not-exists - Determines whether a
record represents an existing item in ContactsLaw. Useful for deciding whether to save a record that the user has not populated.
Hyperlink visited - Determines whether a particular hyperlink control has been clicked during the current session.
Prompt - Displays a prompt to the user at run-time‡, allowing the result of the rule to be determined interactively.
Regular expression - For advanced users only. Determines whether a value matches a
regular expression.
Visibility - Determines whether a particular
section on the form is visible.
Will/won't be saved - Determines whether, based on current conditions, a record will or won't be saved when the form is completed.
‡ - Prompts are only displayed when the user navigates to the next page or clicks the Finish button on the form. Otherwise, the form will behave as though the question had been answered in the affirmative.
Actions
Actions are performed in response to the outcome of a rule. An action may affect other components of the form, such as controls and records. When a rule triggers a set of actions, all actions in the set will be performed in the order in which they appear.
Note: Actions will not cause rules to be re-evaluated. For example, if a rule updates a record when a control's value equals "X", and another rule causes the control's value to be set to "X", the record will not be updated. The order of the rules can be changed to alter this behaviour, but you should not design rules which depend upon each other in this manner. |
The available types of actions include:
- Set value - Sets the value of a control/record to any other value. This is the most common type of action.
- Enable/disable button - Toggles whether a button control can be clicked. Useful for preventing the user from moving to the next page until certain criteria have been satisfied.
- Go to page - Immediately navigates to another page. This can be used to skip over certain pages, or automatically advance to the next page.
- Save/don't save record - Controls whether a record is ultimately saved to ContactsLaw or not. This can be used to prevent empty optional items from being created.
- Show/hide column - Toggles the visibility of a column in a Table control.
- Show/hide page - Toggles an entire page of the form. Hidden pages are skipped when the 'Next' button is clicked and the rules for that page are not evaluated.
- Show/hide section - Toggles the visibility of a section on the page. The bindings on controls in hidden sections are ignored.
- Fail validation - Causes the current page to fail validation (preventing the user from navigating to the next page). This is useful for creating complex validation criteria.
- Submit form - Equivalent to pressing the Finish button on the form.
Rules which run when the user clicks the Finish button offer a different set of actions.
Rule types
Rules can be structured in different ways depending on how they will be used. Several different rule types are offered:
If-Then-Else rule
The most common type of rule. If the conditions are satisfied ("if"), one set of actions is performed ("then"); otherwise, a different set of actions is performed ("else"). The first or second set of actions can be left empty.
Switch-Case rule
This form is useful in situations where you want to test a particular control/record for a range of possible values (and perform a separate set of actions for each possibility).
You begin the rule by deciding the value to examine ("switch"). You then add a separate "case" for each possible value you want to match; a case consists of the value and a set of actions which are performed if the value matches the value being examined. If a value is matched by multiple cases, only the actions associated with the first matching case are peformed. You can also specify a set of actions that are performed if none of the cases result in a match ("else").
Unconditional rule
This type of rule has no conditions and simply performs a set of actions. This is useful in situations where you want to copy values between controls/records or perform advanced binding.
For-Each rule
This is a compound rule. It allows a set of rules to be evaluated once for each item (e.g. control or record) in a list. All items in the list must be of the same type. Within a For-Each rule, conditions and actions can refer to the current item in the list. This removes the need to duplicate rules if the same logic applies to multiple items on the form.
An example of a For-Each rule would be to loop through a list of contacts and create a task for those contacts who have a mailing address. By using a For-Each rule, it does not matter how many contacts are examined; there is still only one rule.
For-Each-Row rule
Similar to the For-Each rule (above), this type of rule evaluates a set of rules once for each row in a table. This can be used to perform bulk updates or calculate running figures.
While-Do rule
This is a compound rule. It allows a set of rules to be evaluated multiple times, for as long as a particular set of conditions are satisfied. The conditions are evaluated before each loop. Similar to the For-Each rule, conditions and actions can refer to a loop counter which keeps track of the number of times the rules have run. Due to the potential for this type of rule to result in an infinite loop (which would crash the program), a hard limit of 5000 loops is applied.
An example of a While-Do rule would be to generate a table of values containing the dates of a recurring event. Rules to add a row to the table and increment the date would continue to run until the date reached a particular value.
See also
Interactive Forms Framework