Get ServiceNow Incident

Not Yet Reviewed

So there are a lot of ways to update service now incidents from an xMatters workflows.  However they all require a Sys_ID, I rarely have access to the sys ID however I always have access to the Incident#.  

I can right a simple java script that that taps the ServiceNow API and returns the Sys_ID by for a corresponding incident#, however I cant seem to get that to run right on a custom step in xMatters

With all the the xMatters to ServiceNow integration that currently exists there has to be an easier way to just reach out the SNow from xMatters and say, "Hey tell me about this Incident#"




Date Votes

Please sign in to leave a comment.

  • Thank you for your feedback. We'll consider how we might make this process easier in the future.

    To provide some background, ServiceNow requires the sys_id to update, add comments, or retrieve a specific record. While users with the appropriate permissions can change the incident number, the sys_id remains immutable. You can search for a record using the incident number, which can be sufficient as it is should be a unique, auto-incremented value. However, if you need to update the record or add a comment, you will still need the sys_id, which can be obtained from the query results.

    Here is a definition for a step to query for an incident by number and output the sys_id.

    Name: ServiceNow - Get Incident by Number

    Endpoint Type: ServiceNow


    • Incident Number


    • Incident Found
    • sys_id
    • You can define more outputs to use in the flow.  They just need to have the same column name (not label) as in ServiceNow.


    output['Incident Found'] = 'false';

    var table = 'incident';
    var incNumber = input['Incident Number'];

    var path = "/api/now/table/" + table;
    var options = "?sysparm_exclude_reference_link=true&sysparm_display_value=true&sysparm_limit=1&sysparm_query=number%3D" + incNumber;

    var request = http.request({
        'endpoint': 'ServiceNow',
        'method': 'GET',
        'path': path + options,
        'autoEncodeURI': false

    var response = request.write();
    if (response.statusCode < 200 || response.statusCode > 299) {
        console.log("ServiceNow returned response code " + response.statusCode);
        return null;
    var payload = JSON.parse(response.body)

    if(payload.result && payload['result'].length > 0){

        var record = payload.result[0];
        for (const key in record) {
          if (record.hasOwnProperty(key)) {
                output[key] = record[key];
              } else {
                  output[key] = "";
        output['Incident Found'] = 'true';
    (Edited )
  • I appreciate you taking the time to respond. 

    Well now I am know I'm not going crazy.  Before making this post I tried a script just like this and I kept getting the same error.  Its like it wont see the existing endpoints. 

     I know this endpoint works cause in the same workflow it does other things that communicate with ServiceNow.

    Script failed with message: No endpoint has been defined with name 'ServiceNow' No endpoint has been defined with name 'ServiceNow'

    (Edited )
  • Is your custom step configured like this?

    Endpoint configuration

    Endpoint reference in script code


Didn't find what you were looking for?

New post