Triggers
Fields of a trigger, which runs a server script before or after a record is created, updated or deleted, how to refuse a save, and two examples.
A trigger runs a server script when a record on its table is created, updated or deleted, for example to set a field from another one. This page lists a trigger’s fields for administrators and developers who write them. You need the administrator role and JavaScript knowledge.
In the Administration workspace, go to Scripting & automation → Scripts → Triggers. The script runs on the server and can use any script library. See Where scripts run.

Trigger fields

| Field | Type | Behaviour | Purpose |
|---|---|---|---|
| Trigger name | Text | Required. | Identifies the trigger, for example “Incident - Location based on Requested for location”. |
| Table | Table | Required. | The trigger runs for records on this table. |
| Field | Field | Optional. When set, the trigger runs only if this field changed. | Limits the trigger to one field’s changes. |
| Description | Text | Optional. | Says what the trigger does, for other administrators. |
| Active | Yes or no | Default yes. | Only active triggers run. |
| Trigger when? | Choice | Required. Default Before. Values are in the next table. | When the script runs relative to the save. |
| On transition(s) | Workflow transitions | Optional. | Runs the trigger only when the record moves along one of these transitions. |
| On create | Yes or no | Runs when a record is created. | |
| On update | Yes or no | Runs when a record is updated. | |
| On delete | Yes or no | Runs when a record is deleted. | |
| Order | Number | Default 10. Lower numbers run first. | Orders triggers of the same table and timing. A later trigger sees field values an earlier one set. |
| Stop on exception | Yes or no | If this trigger fails, later triggers do not run. If a Before trigger fails, no After trigger runs either. | Stops dependent logic after an error, such as a syntax error or a missing field. |
| Overrides | Trigger | Optional. The named trigger, on a parent table, no longer runs for this table. | Replaces inherited logic, for example a Work trigger for Incident only. |
| Script | Script | Required. Receives current, previous and operation. |
The logic to run. |
Trigger when values
| Value | Runs | Use it to |
|---|---|---|
| Before workflow | After default field values are set, before the workflow is chosen and started. | Set fields that a workflow condition or the first activity reads. On transition(s) never matches here, because no transition exists yet. |
| Before | Before the record is written to the database. | Set or check fields on the record itself. You do not need current.update(). |
| After | After the record is written. | Create or change other records, or call an integration. |
| Async | In the background after the save, through the async.trigger system event. |
Work that need not finish before the user sees the save. |
| Clone | While a record is being cloned. The script receives the new copy as current and the original as source. |
Adjust or clear fields on a copy. |
| Export record | While a record is being written to an XML export. Changes appear in the export but are not saved. | Change what an export contains. |
On transition(s), On create, On update, On delete and Field do not apply to Clone and Export record triggers.
Refuse a save
A Before or Before workflow trigger can stop the save with a message the user sees. Call Refusal.refuse(message). The refusal stops the save even when Stop on exception is off.
if (!current.AssignedTo.hasValue()) {
Refusal.refuse("Choose who the asset is assigned to.", ["AssignedTo"]);
}
Name fields as the second argument to have the user fill them in. On a form, those fields appear in the required-fields pop-up with the message. The REST API answers 422 with the message against each field. Refusal.refuseFields(fields) names fields without a message of your own.
Write the message for the user, because it is shown as it is. Any other error in a trigger fails the save with a message that names only the trigger. In an After trigger the record is already written, so a refusal counts as any other failure.
Example: assign an incident to the user who starts work
This Before trigger runs on the transition from New to Work in progress. It sets the assignment group to one of the user’s groups and the assignee to the user.
| Field | Value |
|---|---|
| Table | Incident |
| Trigger when? | Before |
| On transition(s) | The transition from New to Work in progress in the incident workflow |
| On create | No |
| On update | Yes |
| On delete | No |
// Use the current group if the user is a member, otherwise the user's first selectable group
let groupToAssign = "";
let currentGroup = current.AssignmentGroup.value();
let aGroupRec = Table("Group")
.AND(
EQUAL("Selectable", true),
OR(
SUBQUERY("AccessibleFrom", IN("Table", ["Incident"])),
NOT(SUBQUERY("AccessibleFrom"))
),
SUBQUERY("Member", EQUAL("ID", user.getID()))
)
.query();
while (aGroupRec.next()) {
let currentGroupID = aGroupRec.getID();
if (currentGroupID == currentGroup) {
groupToAssign = currentGroupID;
break;
} else if (groupToAssign == "") {
groupToAssign = currentGroupID;
}
}
if (groupToAssign != "") {
current.AssignmentGroup(groupToAssign);
}
current.Assignee(user.getID());
Example: send an incident to another ticketing system
This After trigger calls a script library to send the incident to another system. The other system’s ticket ID is kept in the ThirdPartyReference field. The example assumes a script library named IncidentIntegrationUtil with a function synchToOtherSystem. To write the HTTP call, see HTTP.
| Field | Value |
|---|---|
| Table | Incident |
| Trigger when? | After |
| On create | Yes |
| On update | Yes |
| On delete | No |
let action = current.ThirdPartyReference.hasValue() ? "update" : "create";
let returnMessage = IncidentIntegrationUtil.synchToOtherSystem(action, current);
current.WorkJournal(returnMessage);
// Write only the journal entry: do not run the triggers again
current.disableTriggers();
current.update();