Rules editor
Rules > Rules editor
The Rule Editor is a system form, used by application administrators to create validation or style rules, where an evaluation of the data entered in fields is made in order to allow the user save the form or to format fields with colors. It is located in the Rules folder, under Administration in the navigation menu.
The columns of this form may be filtered and sorted. Multi-level sorting: You can sort more than one column, keeping a specific order, e.g. sort by column "A", then by column "B", and so on. For that, after sorting the first column, hit and hold Shift on your keyboard, and then click on the second column you wish to sort (one click for ascending, two clicks for descending), and then the third column, etc. Note that the order will be indicated by a number together with the sorting arrow icon. |
Create a validation
Open the Rules editor, expand the desired table by clicking on its arrow, hover over the field to be used in the rule and click on the arrow to its right. Click on Validation, to display up to 3 options (depending on the type of the field):
-
E-mail address. Makes a validation of whether the value typed in the field in question matches an e-mail address expression.
-
Phone number. Makes a validation of whether the value typed in the field in question matches a phone number expression.
-
New validation. A custom expression must be provided.
Click on any type of validation and observe that the new rule is added to the table section on the right side of the screen, where information regarding the field and the rule is provided, e.g., the State column will display "Draft" for rules still under configuration.
On the Basic section, optionally edit the Name of the rule and the validation in the Valid when box (to click on the Edit button might be required). Note that a validation can be configured using operators (for Comparison, Logic and Arithmetic), Fields, Functions, constant values, e.g., MyNumberField1 > MyNumberField2 + 10
(see examples of rules at the bottom of this topic), and
regular expressions
(i.e., a special text string for describing a search pattern, e.g., the expression .+\@.+\..+ is a pattern for regular e-mail addreses. More regular expressions can be obtained at regular-expressions.info)
.
To create a rule with a regular expression, select "matches" in Functions drop-down.
For comparisons between numbers and text strings there are conversion functions "as number" and "as string", found in Functions drop-down (select "number" or "string").
For geolocation, the following functions are available: userLocationDistance(latitude, longitude)
to validate the distance, in km, between the user and a certain location; userLocationAccuracy()
to obtain precision of the user’s position; and userLocationAge()
to obtain the age, in seconds, of the user’s last reported position. Note that there are also useful functions for geolocation via rule action formulas and IQL.
For Date and Date time fields, try the functions now, today, addDays and addSeconds. For instance,
Booking date >= today (addDays) plus 1
day would be useful to ensure that the user cannot enter a date earlier than tomorrow.
There is also day()
, month()
, `startOfMonth()
, endOfMonth()
, etc., to compare and limit date and time input in a dynamic way on forms, for example:
Date >= startOfMonth(today()) AND Date ⇐ addDays(endOfMonth(today()), 15)
force the booking of appointments during the current month only, or maximum before the 15th next month.
Date >= startOfMonth(today()) AND date ⇐ endOfMonth(today())
Date must be in this month, or year(Date) = year(today()) AND month(Date) = month(today())
Date > endOfDay(today()) AND ⇐ endOfMonth(today())
Date must be after today but in current month.
Also, HasRole()
is a helpful function, to limit the validation to a certain role.
To test the validation, try setting some values into the field(s) in the Test section. Hit Enter to see below whether it is valid or not.
Optionally, add a Message to user (translations can also be added), which will be displayed as tooltip when hovering over the field(s) used in the rule on the application form, in case the validation fails. Regardless of whether this tooltip message is added or not, a system message will always be displayed warning for invalid fields.
Finally, click on Save and Publish, located at the control bar above the Basic section. Note that the State of the rule is now "Active".'
Click on the Inactive checkbox so you can filter and decide whether or not to keep those inactive rules which you won’t use. |
Additionally, you may verify on the appropiate application form that the rule works as expected.
If the validation fails (i.e., did not match the expression or was not set as required), the user will not be able to save the changes in the application forms that include the chosen field, until it is valid. |
Note that validations are intended to evaluate the data entered on fields in order to proceed saving the form, triggering no action other than showing the default/user message in case the data is not valid. If you want to trigger an action, e.g. set a value to a field, use Rules wizard instead. |
See some examples of validations here.
Create a style
To color the text and/or the background of a field box based on a value set to a field, open the Rules editor, expand the desired table by clicking on its arrow, hover over the field to be modified by the rule and click on the arrow to its right. Click on Style, and then on New style.
A new rule is added to the table section on the right side of the screen, where information regarding the field and the rule is provided, e.g., the State column will display "Draft" for rules still under configuration.
Type the Name of the new style. Mark Color and/or Background color in Style type. Below this, select the Operator, type a value (if applies) and type the color of the text and/or background of your preference (find colors here). For example, let’s say that you chose to set a style to a Drop-down field, so whenever someone selects the item "Cancelled", its background will be set to red. In that case, create a style from that Drop-down, call it "Red cancellation", select Equal to as Operator, type Cancelled as Value/Match and type #FF0000 as Background. Multiple styles can be defined for the same field under the same rule by using the + icon.
Finally, click on Save and Publish, located at the control bar above the Basic section. Note that the State of the rule is now "Active".
After defining this rule, go to Form designer, select the field to be modified by the rule, and choose the newly created style in Style rule under Properties.
Note that Record name can also be subjected to styles. |
Styles will also take effect on markers of Maps. |
See some examples of styles here.
Create an advanced style
To color the text and/or the background of a field box based on a complex condition that may involve multiple fields, open the Rules editor, expand the desired table by clicking on its arrow, hover over the field to be modified by the rule and click on the arrow to its right. Click on Style, and then on Advanced style.
A new rule is added to the table section on the right side of the screen, where information regarding the field and the rule is provided, e.g., the State column will display "Draft" for rules still under configuration.
In the Basic section, add the If function:
-
In the if box, add the necessary condition (read how operators and functions work here).
-
In the then box, type
color:<color>
orbackground:<color>
or combine both separated by a semicolon. -
In the else box, nest an additional If function for further conditions; otherwise, leave it empty.
For instance, an advanced style rule to set the field Status to red with white text in case the delivery of a product is late, would look like this:
If Actual delivery date > Planned delivery date then background:red;color:white
.
Finally, click on Save and Publish, located at the control bar above the Basic section. Note that the State of the rule is now "Active".
After defining this rule, go to Form designer, select the field to be modified by the rule, and choose the newly created style in Style rule under Properties.
Note that Record name can also be subjected to styles. |
Styles will also take effect on markers of Maps. |
See some examples of styles here.
Edit a rule
Open the Rules editor and select the rule to be edited in the table section on the right side of the screen. Note that this selection will highlight the fields used in the rule (and their table, also highlighted) listed in the tree to the left of the screen.
Alternatively, a rule can also be selected from the tree, by first expanding the table, then the field and finally the validation rule. This can be useful in case the list of rule in the table section is very long.
Click on Edit, located at the control bar below the table section.
Edit the rule as you wish.
Click on Save and Publish to activate it after changes are made.