In ServiceNow, all information is stored in tables. The tables refer to each other with reference fields. This documentation shows you how to send and update reference fields with Exalate for ServiceNow.
Read more about reference fields in the ServiceNow Reference field documentation.
- Sending Reference Fields
- Updating Reference Fields
Sending Reference Fields
ServiceNow REST API returns different results when the field is empty or not empty:
- If the field is empty, it returns an empty string value.
- If the field is not empty, it returns an object with the display value and a link to the reference field table.
To send a reference field, we need to make sure that it is not empty with a script:
//Outgoing script if(incident.caller_id && incident.caller_id != ""){ //We only get inside this block if the caller_id has a value replica.caller = incident.caller_id.display_value }
The script returns the display value.
In some cases, we need to retrieve other information with the display value. To do so, we can use a link to the table and nodeHelper.getTableByLink
. This method gets the full content of the reference field.
Example:
//Outgoing script if(incident.caller_id && incident.caller_id != ""){ //We only get inside this block if the caller_id has a value replica.callerMail = nodeHelper.getTableByLink(incident.caller_id?.link)?.email }
You can replace the email
value to get other information, for example, a user name.
If you want to get a specific value from the table, you can use nodeHelper.getReference
. In the script, you can specify the table name.
Example:
//Outgoing script replica.johnUserName = nodeHelper.getReference("sys_user", "email", "john@snow.com")?.name
You can replace the following parameters:
sys_user
- Name of the table.
email
- Name of the table column.
john@snow.com
- The value in the column.
Updating Reference Fields
You can update reference fields by using their sys_id
value.
Example of getting the field status:
//Incoming Script incident.incident_state = "9"
You can also retrieve the reference id by using specific values from a table and a column.
Example:
//Incoming script def remoteEmail = replica.reporter?.email if(remoteEmail){ incident.caller_id = nodeHelper.getReference("sys_user", "email", remoteEmail)?.sys_id }
You can replace the following parameters:
sys_user
- Name of the table.
email
- Name of the table column.
Example of getting a reference id by using a Jira custom field:
//Incoming script //Receiving a value from a Jira Custom Field where the CF name is "Jira Custom Field name" def remoteAssignmentGroup = replica.customFields."Jira Custom Field name"?.value incident."assignment_group" = nodeHelper.getReference("assignment_group", "name", remoteAssignmentGroup)?.sys_id
Have more questions? Ask the community