Triggers
What sets your automation in motion.
What's a trigger?
"Trigger" is a common term when talking about automations, and refers to an event that sets the automation in motion.
It's a cause-and-effect relationship. Every trigger is paired with an action. That is: when the trigger is activated, something will happen. In the case of lowcode automations, this action is whatever you've programmed it to be.
Which triggers can I use?
There are six different triggers on jestor:
- Before a record is created.
- Before a record is updated.
- Before a record is deleted.
- After a record is created.
- After a record is updated.
- After a record is deleted.
As you can see, they reflect the three different actions a user can perform on a record through the interface: create, update or delete.
This is useful to set specific conditions for an automation to run. For example, I may want to automatically assign a random Customer ID for customers on a table. For that, I probably want to use a trigger that is activated when I create a record because I want this customer to have this ID as soon as I insert his information on jestor, and also because this automation only has to run once.
However, you may also have noticed that we have two different triggers for those events, which are the Before and After triggers. The difference may not be obvious at first, but it's an important distinction that heavily impacts certain automations, as it relates to whether information has already been written on the database or not.
Before and After
To understand the difference between Before and After, we have to understand how data is written on a table, chronologically speaking.
Whenever a user performs an action through the interface, there's two different moments: before the information they're sending is actually written on the database, and after the information is written.
When you choose a before trigger, your automation will run in the (1) moment. How does that impact automations?
- If you change the values inside the $objectNew array, the new values are the ones that will be written on the database.
- If you perform a search on the table that triggered the automation, the information sent by the user will not turn out on the search because they aren't yet written on the database. That means if your user created a record, the entire record will not come up on the search. If they're updating a record, the old values will come up on the search. If they're deleting a record, it'll still turn up on the search.
- If the user is creating a record, $objectNew will still not have an id, because the record wasn't actually created yet.
Similarly, if you choose the after trigger, your automation will run in the (3) moment, which means:
- If you change the values inside the $objectNew array, the it'll not change the record's data to reflect those changes, as the information was already written on the database.
- If you perform a search on the table that triggered the automation, the information sent by the user will appear on the search because they already written on the database. That means if your user created a record, it'll come up on the search. If they're updating a record, the new values are the ones that will come up on the search. If they're deleting a record, it'll still not turn up on the search.
Choosing the appropriate moment for the trigger is just as important as the action itself, and will directly affect the way you'll need to code your solution.
Updated over 3 years ago