When, where and how are rules executed in Easit GO?
Knowing when to choose which type of rule to use can be a bit of a challenge, but it doesn’t have to be. For the die-hard, the names may be self-explanatory, but for the newly converted “Easitian” it may not be entirely obvious. In this post, I will therefore go through the different types of rules that exist, when it may be appropriate to use which type and when not to. Remember, however, there are many ways to skin a cat.
Execution flow
Before we go into the different types of rules that exist, we need to go through the “flow” of how a rule is evaluated and executed. Roughly divided into three steps:
- An event occurs in the system
- Evaluation
- Running/Execution
When a form field changes value, or an object is saved, this is called an event. When an event occurs, the system checks which rules are listening for this event. These rules are set to react to changes in certain field values – rules that react to the fields that have changed value are filtered out.
The field rules set in the rule are then evaluated to see if the form or object that triggered the event meets them. If the form or object meets the field rules, the rule is run on the form or object, otherwise the rule is skipped.
Form rules
This type of rule is evaluated and executed only when an object (e.g. a contact or organization) is opened or values in a form are changed. Forms are used to display objects, different forms can be used for different roles in the system. It is not possible to run form rules without visually “opening” the object.
In a rule, you can select one or more fields as 'Changed fields'. If a field is selected as a changed field in a rule, this field MUST be set on the form to trigger an event. If you select, for example, Country as a changed field in a rule but Country on the form does not trigger an event, the rule will not be evaluated or executed.
It's perfectly fine, but not necessary, to run one rule for both events, and it's just as easy to have two rules that do the same thing, but one runs for each event. It all depends on your needs and circumstances.
If you choose to have multiple fields as Changed fields in a form rule, only one field needs to change for the rule to be evaluated. If the rule has multiple fields as Changed fields and several of these change, the rule will be evaluated once per changed field. All fields do NOT need to be changed.
When a form is loaded (ON_FORM_LOAD)
When you open an object, whether it is via e.g. a view or direct link, an event is triggered in the system called ON_FORM_LOAD and is one of the 2 events that trigger form rules. Things you might want to do here are (there are probably more than these):
- Hide or disable fields if a certain condition is met.
- Set default values in fields.
- Setting filters on object search fields
When a form changes (ON_FORM_CHANGE)
The second event that triggers form rules is when a form changes, i.e. if you change the status of a case (not if you change how the form looks) and is called ON_FORM_CHANGE. Depending on how much dynamism you want in the form, probably a lot, the same things that are performed at ON_FORM_LOAD can also be performed here. For example, you might want to filter applicants based on which organization is selected in a case, calculate priority based on impact and urgency, or show the Solution field when the status is set to Solved.
Tips from the coach
Remember to select a field under 'Changed fields'. *wags index finger*
If you create a rule that does not have a field as a changed field, the rule will be evaluated and potentially executed for every field that triggers an event. This can cause the rule to run at the wrong time and create unexpected side effects.
Object rules
Rules that run when you click Save, or answer Yes to the question of whether you want to save the changes made to the object when you try to “walk away from the object” are called Object Rules. Just like form rules, there are two events associated with these rules, these are ON_ITEM_SAVE and ON_AFTER_ITEM_SAVE. Object rules run regardless of how a change is made to the object and use a “before-after” scenario to know when to run. For example, a rule can run if the priority changes from 5 to 1.
Unlike form rules, for object rules you can decide whether All or at least one field needs to change for the rule to run. This means that if I have selected Status and Type as changed fields, I can choose whether both or only one of these must change for the rule to be evaluated.
As I mentioned earlier, a “before-after” scenario is used to configure when a rule should and should not be run. This means that you compare the values of the object from before you click Save with what the field has when you select Save. That is, what the object had for values with what it will get for values.
When an item is saved (ON_ITEM_SAVE)
The first event that occurs when you choose to save an item is ON_ITEM_SAVE and at this event you can still change the values of the item that will be saved. For example, you could choose to retrieve the organization from the Owner (Contact) on an inventory and put that organization in the Owner (Organization) field when the Owner (Contact) changes.
After an item is saved (ON_AFTER_ITEM_SAVE)
The second event that occurs is ON_AFTER_ITEM_SAVE and unlike the previous event, you can NOT change the values of the object that is saved here. Things you might want to do with this event are sending automatic emails or communicating with external systems.
Tips from the coach
Always, ALWAYS, run the following functions only at ON_AFTER_ITEM_SAVE.
- Auto email
- Export objects
- Update subobjects with data from the parent object
Since the values of the object can change after a rule is run at ON_ITEM_SAVE, you don't want to send these values before all possible changes have been made. Suppose you want to send a confirmation to the person reporting a case with information that they will be contacted as soon as the case is started when the status is set to Registered. If you were to run the rule that sends the confirmation at ON_ITEM_SAVE, there could potentially be a rule that sets the status Waiting for customer after the rule that sends the confirmation, and then you end up in a situation where both parties are waiting for each other, the customer for us and we for the customer. Maybe not the most common scenario, but you get the idea.
Message rules
Say you want the status to be set to pending if an email is sent to a case, this can be controlled by message rules. These are rules that run when an email is imported into an object. So these are not rules that run when a message is sent from the system.
For example, you may want to check the message for foul language, classify images in the message, or change the status. These are some of the things that can be done when a message arrives.
Tips from the coach
There are things that can be done by both message rules and object rules, such as changing the value of a field or sending a notification to the case manager that a new email has been received for the case.
If you are careful that right is right, you should, for example, run rules that notify administrators as a message rule, otherwise the order of emails on the Email tab will be wrong. If the notification message were to be sent with an object rule, it would end up before, chronologically, the message that the customer sent in. Not the whole world maybe, but it looks a bit crazy, I think. And right should be right.
Escalation rules
Sometimes you may want to perform things in the system according to a schedule (every Monday) or you may want to continuously check whether an object meets a certain condition and if it does, perform something. In these cases, escalation rules are ideal. The system has something called a background job that normally runs every 10 minutes. This can be changed so it may not be the case for you. The system then evaluates objects with the conditions set in all escalation rules and if any object meets these, the rule is executed. For example, you may want to send a reminder to the contract manager 3 months before a contract expires or you may want to close all cases that have not been updated in 1 month.
Examples of functions that can be used in an escalation rule are:
- Auto email
- Archive items
- Delete item
- Change object fields
There are also more functions, but there are functions that can only be performed by object rules, and what you can take with you is that you can trigger object rules, since the object is saved when changed and thus triggers ON_ITEM_SAVE and ON_AFTER_ITEM_SAVE, with escalation rules. For example, an escalation rule can change a field on an object that makes the object meet the conditions for an object rule.
Quick Functions - “Ninja Object Rule”
Let's say you're looking at a view and see 7 objects that all need the same steps performed on them, then you can use a Quick Function. Quick Functions are a bit like an escalation rule fast on demand. Right-click on an object in a view, select the quick function you want to perform, possibly make the required selections, done.
Quick Functions are configured in the same way as a form rule, minus changed fields. If an object in a view does not meet the quick function's conditions, the quick function is hidden. Quick Functions have a neat addition, Ask verification question before execution. This addition gives the user of the quick function the opportunity to undo. It can be good to have checked if the quick function, for example, uses the Delete object function. 😊
Examples of common scenarios where quick functions can be used are:
- Set yourself as the case manager and start cases.
- Removing a contact as owner will remove all of their inventory.
- Change account manager for organizations or agreements.
Final words
I hope this post hasn't created more question marks about the rules than you had before, but if that's the case or if you have any follow-up questions about this, don't hesitate to contact me via email, LinkedIn or another method that suits you!
Anders Thyrsson
Email: anders.thyrsson@easit.se
Github: https://github.com/easitanth
X: https://x.com/easitanders
LinkedIn: https://www.linkedin.com/in/easitanders