NOTE: This documentation was written based on ServiceNow documentation at the time of release. Check ServiceNow for the most current documentation.
Create a ServiceNow incident when a SysTrack sensor notification activates. In ServiceNow, you create a scripted REST API that receives the webhook request from SysTrack and creates the incident. In SysTrack, you add the API as a webhook recipient and add the recipient to a sensor notification.
NOTE: In SysTrack On-Premises, the Tenant ID (
@{tenantId}) in the examples is always an empty GUID (00000000-0000-0000-0000-000000000000).
Create a Scripted REST API in ServiceNow
NOTE: You must have the web service administrator role to work with scripted REST APIs.
Log into your ServiceNow account.
In the search field, type Scripted REST APIs.
In System Web Services > Scripted Web Services, select Scripted REST APIs.

Click New to create a new API service.
Enter a name and API ID. For this example, we use systrack connection.

Click Submit.
In the Name search bar, enter the API you just created, systrack connection.

Click the link that pops up.
Scroll to Resources and click New.
In Name, enter event.
In HTTP method, select POST.
Scroll to the Script section and paste your code snippet.

NOTE: Use this as a starting point for your script and modify it to represent how you want SysTrack information displayed as your ServiceNow incident.
Update the script:
Set
secretto your own secret, a random string. Save this value. You add it as a header in SysTrack in step 16.In the line
inc.assignment_group.setDisplayValue("Developer");, changeDeveloperto the group that the incidents are assigned to.
IMPORTANT: The example script that follows gets the apiKey from headers instead of from the URL.
The example script below expects a secret of "1VX4YABggw".
var secret = "1VX4YABggw";
You can change the secret variable to whatever secret value you would like.
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { gs.warn("Scripted webhook /api/laso/systrack called."); var apiKey = request.headers.apikey; var secret = "1VX4YABggw"; if (apiKey == secret) { var event = request.body.data; // Parse the JSON data in the request body var inc = new GlideRecord('incident'); inc.initialize(); var short_description = "Sensor Notification activated - "; short_description += event.data.notificationName; inc.short_description = short_description; var desc = "The sensor notification " + event.data.notificationName + " was triggered."; desc += " The notificaton was triggered because at least " + event.data.activationString; desc += " had the following sensor(s) active: " + event.data.sensorString + ".\n\n"; desc += "To view more details for this activation, please navigate to the following SysTrack URL: "; desc += event.preventURL; inc.description = desc; var formattedNotification = "Notification: " + event.eventType + "\nEvent ID: " + event.eventId + "\nEvent Time: " + event.eventTime + "\nTenant ID: " + event.data.tenantId + "\nNotification Name: " + event.data.notificationName + "\nSensor Names: " + event.data.sensorNames.join(', ') + "\nGroup Name: " + event.data.groupName + "\nActivation: " + event.data.activation + "\nIs Percent: " + event.data.isPercent + "\nNotification Description: " + event.data.notificationDescription; inc.work_notes = formattedNotification; inc.assignment_group.setDisplayValue("Developer"); inc.insert(); } else { gs.warn("Invalid API Key for Systrack Connection Webhook"); } response.setStatus(200); })(request, response);NOTE: The script provided is for creating an incident in ServiceNow, but you can adjust it to create another ticket type. See ServiceNow documentation for more information.
In Security, deselect Requires authentication. We are using the secret variable to protect access to the API.
Click Submit.
In SysTrack, unlock Configure for editing (see Unlock for Editing). Go to Configure > Sensor Configuration > Notifications, select the Recipients tab, and add a webhook recipient. See Webhook Support for Sensor Notifications. Use these values:
URL: the URL of the scripted REST API resource that you created.
Request Method: POST.
Headers (Optional): a header with the name
apiKeyand your secret as the value. Select Sensitive to hide the value after you save.Body: the template in Webhook Body Template for ServiceNow, below.
Click Add Recipient, and add the recipient to a sensor notification. See Manage Sensor Notifications.
To check the setup, wait until the sensor notification activates. A new incident appears in ServiceNow.
Webhook Body Template for ServiceNow
Copy and paste this content into Body in the Add New Recipient dialog box, and edit it as needed. For the variables you can use, see Sensor Notification Webhook Body Templates.
{
"eventId": "@{notificationActivationId}",
"eventTime": "@{activationTime}",
"eventType": "SensorNotification.Activated",
"data": {
"tenantId": "@{tenantId}",
"notificationName": "@{notificationName}",
"sensorNames": [@{sensorNames}],
"groupName": "@{groupName}",
"activation": @{activationThresholdValue},
"isPercent": @{activationThresholdIsPercent},
"notificationDescription": "@{notificationDescription}",
"sensorString": "@{sensorNamesUnquoted}",
"activationString": "@{activationThresholdText}"
},
"systemsAffectedURL": "@{systemsCurrentlyAffectedURL}",
"preventURL": "@{notificationActivationDetailsURL}"
}