Notification Scripts
Use the notification scripts to dynamically change the parameters of the outgoing messages using the SimpleEmailOutbound class.
You can use the same script in multiple email notifications and notification templates. To do so, add a ${script:script_name}
embedded script tag to the notification rule or to the related notification template. You can use the embedded scripts in the following fields:
- Subject
- Message
- Message (HTML)
- Other
To create a notification script, complete the steps below:
- Navigate to System Notification → Notification Scripts.
- Click New and fill in the fields.
- Click Save or Save and exit to apply the changes.
Notification Script form fields
Field | Mandatory | Description |
---|---|---|
Name | Y | A script name for later usage in notifications and templates. The name should not contain spaces. |
Script | Y | Enter the script using SimpleOne server-side API, particularly, the SimpleRecord Server-Side, SimpleEmailOutbound and SimpleTemplatePrinter classes. There are four objects available in the notification scripts:
|
To receive the values of the current and event objects, use the dot-notation to address the properties relating to the column names of the current and Events (sys_event) tables. See the example below:
(function runNotificationScript(
/* SimpleRecord */ current,
/* SimpleTemplatePrinter */ template,
/* SimpleEmailOutbound */ email,
/* SimpleRecord */ event
) {
email.setSubject(current.number + '- additional comment has been added');
email.setBody(`A comment from: ${event.sys_created_by.display_name}: "${event.param_2}"`);
if (current.days_count > 3 && !current.requester.vip) {
email.addAddressCc(current.requester.email, current.requester.display_name);
}
})(current, template, email, event);
To locate where the notification scripts are used, filter the records in the VCS Records (sys_vcs_record) table using the condition builder by the following conditions:
- Navigate to Configuration Pack → VCS Records.
- Click on the funnel icon on the top to open the condition builder.
- Create a filter containing the conditions listed below:
- JSON copy CONTAINS script:script_name
- Table name IS NOT sys_notification_script
- Is current IS Yes.