Examples of rules
Rules > Examples of rules
Besides reviewing the examples of rules below, read also important remarks about additional and recursive rules.
Enter today’s date after approving an order
Description: Once a purchase order ticks and saves its "Approved" checkbox, today’s date value will be automatically entered in the "Approved on" date field.
Target table: Purchase order
Trigger table: Purchase order
Criteria: Checkbox "Approved" = (Absolute) 1
Action: Set the value of a field. Field: Date "Approved on". New value: Today
Rule group: Ungrouped/Normal group
Set access rights to a specific subcontractor
Description: Once a work order selects and saves a "Subcontractor" = "Acme Co.", the work order record will move from the "STANDARD" record group to the "Subcontractor Acme Co." group, which will imply a different set of rights.
Target table: Work order
Trigger table: Work order
Criteria: Drop-down "Subcontractor" = (Absolute) "Acme Co."
Action: Set access rights on record. Move record to record group: "Subcontractor Acme Co."
Rule group: Ungrouped/Normal group
Set access rights to any subcontractor
Description: Once a work order selects and saves a "Subcontractor", the work order record will move from the "STANDARD" record group to the selected subcontractor group, which will imply a different set of rights.
Target table: Work order
Trigger table: Work order
Criteria: Drop-down "Subcontractor" = (Keyword) CHANGED
Action: Set the value of a field with a formula. Type: Text/Note. Checkbox "Record moved to correct group" = moveToRecordGroup(VALUE("Subcontractor"))
Rule group: Ungrouped/Normal group
Send an e-mail to the manager after a customer record is created
Description: Every time a new Customer record is created, send an e-mail to the manager notifying this.
Target table: Customer
Trigger table: Customer
Criteria: (Record keyword) Customer = CREATED
Action: Send a mail. To: Role Manager.
Rule group: Ungrouped/Normal group
Count the number of completed suborders and set the result in the main order
Description: Once "Suborder completed" is ticked and saved in the Suborder form, the "Number of suborders completed" in the Order table will be updated with the count of all Suborders with the "Suborder completed" checkbox ticked.
See more examples of formulas with functions.
Target table: Order
Trigger table: Suborder
Criteria: Checkbox "Suborder completed" = (Absolute) 1
Action: Set the value of a field with a formula. Type: Numeric. Number "Number of suborders completed" = countFields(REF(Order), REF(Suborder completed))
Rule group: Ungrouped/Normal group
Send e-mail 2 days before estimated arrival
Description: In case a shipment’s "ETA" date (Estimated time of arrival) is entered and the "Arrival date" is empty (i.e., the shipment has not arrived), the users assigned to the Logistics team will receive an e-mail notifying that the shipment will arrive, two days before the date specified in the "ETA". As stop condition (a value that, when reached, refrains the rule from evaluating additional criteria and subsequent action) we have the "Arrival date" field, which after entered, will stop the comparison of "today’s date plus two" with the "ETA" date and the e-mail sending for the record in question.
Target table: Shipment
Trigger table: Shipment
Criteria: "Arrival date" = (Keyword) Has no value
AND "ETA" = Today + 2
Action: Send a mail. To: Team Logistics.
Rule group: Scheduled group (DAY schedule)
Sum the salaries of accountants of a company
Description: For a company, sum the salaries of the employees that have position = “Accountant”.
Target table: Company
Trigger table: Employee
Criteria: Drop-down "Position" = (Keyword) CHANGED
Action: Set the value of a field with a formula. Type: Numeric. Number "Accountant salaries" = sumFields(REF(Company), REF(Salary), notused, notused, REF(Position), REF(Accountant))
Note that, in this case param3 and param4 are not used (their purpose is to set upper and lower bounds), param5 is a drop-down field and param6 REF(Accountant) must be manually typed like REF(100301) in the formula, where 100301 is the Field ID of the value "Accountant" that belongs to the list of the drop-down "Position". Field Id’s can be found via the Field usage report in Data model editor.
In other cases, param6 can be simply typed as text in quotation marks or as a number. For instance, sumFields(REF(Company), REF(Salary), notused, notused, REF(Year), 2012), to sum the salaries of employees during 2012.
Rule group: Ungrouped/Normal group
Change the URL of a Link field
Description: The URL of a website is automatically set or change depending on the provider selected.
Target table: Order
Trigger table: Order
Criteria: Drop-down "Provider" = (Keyword) CHANGED
Action: Set the value of a field with a formula. Type: Text. Link "Website" = concat("www.", VALUE(Provider), ".com")*
*If no protocol is specified, "http://" will be set by default.
Important remarks about additional rules and recursive rules
About general execution of actions, if the criteria evaluate to True, the rule is triggered and processing of the rule action starts. But if the criteria evaluate to False, no action is taken. Therefore, if you want different actions to be taken, according to whether the criteria are evaluated as True or False, you will need to write two rules: one, considering the original criteria you wish; and another, considering the opposite criteria in order to have a different action. For instance: Rule #1 Criterion: "Status" = "Ongoing Action: Set format to "Status" field <background=green> This means that every time a user chooses the value "Ongoing" to the field "Status" on a record, the background of this field box will turn from white (which is the original color of any field box) to green. Once this is done, let’s say that another user edits the same record by changing the field "Status" from "Ongoing" (which is still in green) to "Postponed". This action will not return the field box to white. It will remain green, which can be confusing for the users of the application. That is why a second rule needs to be created: Rule #2 Criteria: "Status" = "Cancelled" OR "Status" = "Postponed" (meaning "other values that are not "Approved") Action: Set format to "Status" field <background=white> |
Caution must be taken when creating rules, in order to avoid circular references (i.e., recursive rules) that end up in an infinite loop. For instance, the following rules, Rule #1 Criterion: "FieldA" = 1 Action: Set the value of a field "FieldA" = 2 Rule #2 Criterion: "FieldA" = 2 Action: Set the value of a field "FieldA" = 1 where the result of a rule triggers a second rule that triggers once again the initial one That is the reason why the setting "Only trigger once" should be checked when creating a rule. Otherwise, a message will be displayed in application forms warning about the recursing attempt, and the record(s) with such a triggered field will be skipped while trying to import (which will be notified as a remark in the import log), however the remaining records in the import file will be normally imported. |