Servicely Administration
Scripting
Trigger
5 min
overview a trigger automates business logics before/after a record creation/update/deletion for example, a trigger can automatically set a record’s field to a particular value, after you make a certain change on that record it runs on the server side, has access to the current record being created/updated/delete and access to classes and functions within script libraries javascript knowledge is required creating a trigger field name field type description example trigger name string name of the trigger incident location based on requested for location table reference records on this table will run this trigger incident field reference if nominated, the field here have to change before the trigger runs description text for administrative purposes, provide information what trigger is about set an incident’s location based on requested for’s location if it isn’t set yet active boolean if active, run the trigger yes trigger when? choice before runs the trigger before the record is saved into the database before is recommended if your business logic is to modify/enforce some of the current record’s fields doing those prior to writing into the database will save the number of database transactions in other words, you can set values without writing current update() do not update the current record in a before trigger (i e do not include current update()); after runs the trigger after the record is saved into the database after is recommended if your business logic is to create/update/delete records on other tables or make api calls, etc as you want the changes for the current table to be written into the database first async runs the trigger asynchronously and not sequentially/directly after a record is saved into the database before on transition(s) multiple reference workflow transition(s) off the table’s workflow on create boolean if set to yes, the trigger will run when the record is about to be created checked on update boolean if set to yes, the trigger will run when the record is about to be updated checked on delete boolean if set to yes, the trigger will run when the record is about to be deleted unchecked order integer determines the order of when this trigger should run relative to other triggers for the same table that match the same conditions (trigger when? on transitions(s), on create, on update and on delete) the lower the order results in the trigger to run earlier this will mean if you reference a field that is set of a trigger that runs earlier than another one, you can access the changed script in the later trigger 20 stop on exception boolean if set to yes and this trigger hits an exception/error, then other triggers that are supposed to run after this one, will not run if this trigger runs on before and it hits an exception, all triggers running on after will not run either example of exception includes if you have syntax issue or you are trying to access a non existent field or relationship of a table no overrides reference if this trigger is to override specific triggers running on the table’s parent table when set, the trigger nominated in this field will not run script script the script you want run to automate business logic of your choice within the script, you have access to the current record via the “current” object + the previous version of the record via the “previous” object you also have information on the operation currently executed via the “operation” variable the possible values returned by “operation” is either “create” or “update” or “delete” updating current record’s fields here does not require a current update() if the trigger runs “before” as the record creation/update hasn’t been written into the database yet including it will potentially cause a recursive trigger call examples the following is aimed to give some general examples of what triggers can be used for/can do you may also look at out of box triggers for reference such as the ones for incident management or request management auto assign an incident to a user that progresses it from new to work in progress field name value table incident trigger when? before on transition(s) whatever it is to transition workflow status from new to work in progress refer to workflow on create false (unchecked) on update true (checked) on delete false (unchecked) script on creation or update of a user account, synchronise to the conversation user account table, for whatsapp sofi chat purposes field name value table user trigger when? after on create true (checked) on update true (checked) on delete false (unchecked) script make an api call to synchronise an incident across to another ticketing system, using thirdpartyreference field that captures the other system’s ticket id this requires the use of a script library in this example, we would need one created called “incidentintegrationutil” that has a function called “synchtoothersystem” creating code to make outbound http api calls, you can refer to outbound http requests (scripted) field name value field name value table incident trigger when? after on create true (checked) on update true (checked) on delete false (unchecked) script