ServiceNow - Outbound REST with a Business Rule

Using ServiceNow (SNOW) Outbound REST and Business Rules with SnapLogic.
This document defines the steps required to create a Business Rule and REST Endpoint in ServiceNow that will call a SnapLogic pipeline. Business rules allow the user to define conditions that will trigger an Outbound REST Message when an expression or expressions are evaluated.

Using the sample pipeline as a template create a pipeline and triggered task (associating your SNOW account with the ServiceNow Query snap).

NOTE – 1: this pipeline is setup to accept a POST and is ASYNC – sending back just the RUUID though no additional processing is done against it in SNOW once returned

NOTE – 2: A pipeline parameter called ‘Inc_Number’ has been setup and is used in the query snap

Copy the Bearer Token and URL for use the newly created task:

Next create an Outbound REST Message in ServiceNow.
Go to SNOW and type “REST” in the Navigator Search
Under ‘Outbound’ click ‘REST Message’

Create a New Message, pointing to the triggered URL + “?” + QueryParams

NOTE: You will need to remember the Name (eg. EB – Snaplogi – Send Incident) and variable (ex. ${IncidentNumber}) as both will be used during the script process for the business rule

This should create the HTTP Methods for you – I have POST only but you could also use other methods as needed based on the use case. GET would have also worked in this scenario since I’m only passing Query Parameters to the endpoint

The Next step is to create a Business Rule which references the created REST (under System Definition)

Setup a new business rule

  • select the table / SNOW Object (eg. Incident)
  • Because we are scripting the REST call, you’ll need to select “Advanced” in the top section
  • select desired ‘When to run’ options (eg. before / insert / update / delete) and any filter conditions needed

In the Advanced area on the bottom, you’ll need to add in the following script, substituting your specific values from above for the RESTMessageName and VARIABLE_NAME

function onBefore(current, previous) {
   //This function will be automatically called when this rule is processed.

   var  incnum =current.number;
   var r = new RESTMessage('<RESTMessageName>', 'post');
   r.setStringParameter('<VARIABLE_NAME>',incnum);

   var response = r.execute();
}

Done! Test the rule by editing an Incident in ServiceNow and seeing if the pipeline was triggered.

Here is a dashboard view of the pipeline execution:

And the file created in the middle SNOW Query Path: