In all scripts, regardless of type of entity used, there are some common variables available:
Variable |
Description/Type |
NowUtc |
datetime, same as DateTime.UtcNow |
DayAgoUtc |
datetime |
WeekAgoUtc |
datetime |
MonthAgoUtc |
datetime |
CurrentUser |
User-object |
db |
Object for interacting with db (queries). |
api |
Object providing help methods. |
record |
The record that the Trigger is executed on. |
Most important variable is “record”, which is the entity that is the focus of the Trigger. Either because of it is saved (Event trigger) or because of a Scheduled trigger check. You can make any change to this object and the changes will be committed to database automatically. Any change that is made might also cause other triggers to execute, if the changes caused their conditions to evaluate to true.
When working with fields in scripts you have to use their system names, for instance v:record.BaseHeader. What you see in the GUI is only the field label. This makes it tricky when writing scripts and a big reason why it is wise to consult with Nilex first. There is no autocomplete functions in the script-editor that helps you find the correct name. The workaround for this is to open NSP in another tab and go to the email template editor and do like this:
1. Open NSP in another tab or browser
2. In Agent portal go to Configurations> Manage> Text templates
3. Create a new template, choose Target: Email.
4. Choose the same entity in the Tags field, as you have chosen in the Trigger.
5. Place the cursor in the text field.
6. Find the field you are looking for in the list under the Tags field. Double click on the field and the system name will be written in the text field.
For reference-fields (fields that point to other objects, often shown as drop-downs in UI), it is important to know that in a scripting, they are converted to plain integers Ids.
Example: The Ticket property Priority (field label) has the system name v:record.Priority, but as it is a reference field you should write record.PriorityId in the script.
Common ticket fields cheat sheet
A list of, in scripts, commonly used field names and their script data type.
Field lable |
Script name |
Type |
Agent group: |
record.AgentGroupId |
int |
Agent: |
record.BaseAgentId |
int |
Category: |
record.CategoryId |
int |
Closed date: |
record.CloseDateTime |
datetime |
Created date: |
record.CreatedDate |
datetime |
Description: |
record.BaseDescription |
string (html) |
End User: |
record.BaseEndUserId |
int |
Impact: |
record.ImpactId |
int |
Latest update: |
record.UpdatedDate |
datetime |
Major incident: |
record.IsMajor |
boolean |
Priority: |
record.PriorityId |
int |
Reported by: |
record.ReportedById |
int |
Status: |
record.BaseEntityStatusId |
int |
Subject: |
record.BaseHeader |
string |
Ticket number: |
record.ReferenceNo |
string |
Urgency: |
record.UrgencyId |
int |
Any field that is added from entity editor will be prefixed with “u_”.
Field calculations and null-values
All fields are initially null and it is not possible to use null-values in numeric calculations. This means that there first need to be conversions from null to 0 in the fields used. This is easiest done with the “||”-operator which basically means, if the value to the left of operator is null, use the right-side value instead. For example:
var value1 = record.u_Value1 || 0;
var value2 = record.u_Value2 || 0;
record.u_SumOfValues = value1 + value2;