---
title: Trigger
slug: v111/trigger
icon: {"faIcon":"fa-solid fa-person-running"}
docTags: 
createdAt: 2025-06-10T06:44:31.749Z
---

# 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.

:::hint{type="warning"}
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.<br />ℹ️ 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().<br />⚠️ **Do not update the current record in a before trigger (i.e. do not include current.update());**<br /><br />After: Runs the Trigger after the record is saved into the database<br />ℹ️ 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.<br /><br />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.<br />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.<br />- Within the script, you have access to the current record via the “current” object + the previous version of the record via the “previous” object.<br />- You also have information on the operation currently executed via the “operation” variable.<br />- The possible values returned by “operation” is either “create” or “update” or “delete”.<br />⚠️ 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.                                                                                                                                                                                                           | if (!current.Location.hasValue() && current.RequestedFor.hasValue()) \{<br />current.Location(current.RequestedFor().Location.value());<br />}<br />Please refer to the Examples section below for other  examples/use cases.  This primarily uses the [Table API (Server)](docId\:Jv5jxVD7j4UkkYs-_MUiN) and[User Object (Client and Server)](docId\:LInNoHio1ZYyKAZd_NlSs) (Server side only). |

# 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           | // set the group (either one of the user's groups or the currently assigned group if the user is a member of it)<br />let groupToAssign = "";<br />let currentGroup = current.AssignmentGroup.value();<br />let aGroupRec = Table("Group")<br />.AND(<br />EQUAL("Selectable", true),<br />OR(<br />SUBQUERY(<br />"AccessibleFrom",<br />IN("Table", \["Incident"])<br />),<br />NOT(<br />SUBQUERY(<br />"AccessibleFrom"<br />)<br />)<br />),<br />SUBQUERY(<br />"Member",<br />EQUAL("ID", user.getID())<br />)<br />)<br />.query();<br /><br />while (aGroupRec.next()) \{<br />let currentGroupID = aGroupRec.getID();<br />if (currentGroupID == currentGroup) \{<br />groupToAssign = currentGroupID;<br />break;<br />} else if (groupToAssign == "") \{<br />groupToAssign = currentGroupID;<br />}<br />}<br /><br />if (groupToAssign != "") \{<br />current.AssignmentGroup(groupToAssign);<br />}<br /><br />// finally set the assignee<br />current.Assignee(user.getID()); |

 

**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         | // If user's mobile number has changed<br />if (current.Mobile.hasChanged() && current.Mobile.hasValue() && current.Active() && !current.LockedOut()) \{<br />let number = current.Mobile();<br />if (number.startsWith("+")) \{ // Whatsapp doesn't like +<br />number = number.replace("+", "");<br />}<br /><br />let cuaRec = Table("ConversationUserAccount")<br />.EQUAL("User", current.getID())<br />.query();<br />if (cuaRec.next()) \{<br />// if there is already a conversation user account for the user, update it<br />cuaRec.ExternalID(number);<br />cuaRec.ExternalDisplayName(current.displayValue());<br />cuaRec.update();<br />} else \{<br />// if there isn't already a conversation user account for the user, create it<br />cuaRec = Table("ConversationUserAccount").newRecord();<br />cuaRec.ExternalID(number);<br />cuaRec.User(current.getID());<br />cuaRec.ExternalDisplayName(current.displayValue());<br />cuaRec.create();<br />}<br />} else if (current.Mobile.hasValue() && ((current.Active.hasChanged() && current.Active() && !current.LockedOut()) \|\| (current.Active() && current.LockedOut.hasChanged() && !current.LockedOut()))) \{<br />// if user's mobile number hasn't changed but user has been re-activated<br />let number = current.Mobile();<br />if (number.startsWith("+")) \{ // Whatsapp doesn't like +<br />number = number.replace("+", "");<br />}<br /><br />let cuaRec = Table("ConversationUserAccount")<br />.EQUAL("User", current.getID())<br />.query();<br />if (!cuaRec.next()) \{<br />cuaRec = Table("ConversationUserAccount").newRecord();<br />cuaRec.ExternalID(number);<br />cuaRec.User(current.getID());<br />cuaRec.ExternalDisplayName(current.displayValue())<br />cuaRec.create();<br />}<br />} else if ((current.Active.hasChanged() && !current.Active()) \|\| (current.LockedOut.hasChanged() && current.LockedOut())) \{<br />// if user is deactivated or locked out, delete the conversation user account record<br />let cuaRec = Table("ConversationUserAccount")<br />.EQUAL("User", current.getID())<br />.query();<br />if (cuaRec.next()) \{<br />cuaRec.delete();<br />}<br />} |

 

**Make an API call to synchronise an Incident across to another ticketing system, using ThirdPartyReference field that captures the other system’s Ticket ID**

:::hint{type="info"}
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)&#x20;
:::



| **Field name** | **Value**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Table          | Incident                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| Trigger when?  | After                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| On create      | True (Checked)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| On update      | True (Checked)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| On delete      | False (Unchecked)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| Script         | if (current.ThirdPartyReference.hasValue()) \{<br />// if this ticket is already linked to another system's ticket<br />// NOTE: for this example, we are assuming here that we have a Script Library called "IncidentIntegrationUtil" that packages the API payload and send across to the other system<br />let returnMessage = IncidentIntegrationUtil.synchToOtherSystem("update", current);<br />current.WorkJournal(returnMessage);<br />current.disableTriggers();  // we do not want to cause a loop by running other Triggers as we only want to write to the Work Journal<br />current.update();<br />} else \{<br />// if this ticket is not linked to another system's ticket yet<br />// NOTE: for this example, we are assuming here that we have a Script Library called "IncidentIntegrationUtil" that packages the API payload and send across to the other system<br />let returnMessage = IncidentIntegrationUtil.synchToOtherSystem("create", current);<br />current.WorkJournal(returnMessage);<br />current.disableTriggers();  // we do not want to cause a loop by running other Triggers as we only want to write to the Work Journal<br />current.update();<br />} |

