cancel
Showing results for 
Search instead for 
Did you mean: 

ServiceNow - Outbound REST with a Business Rule

ebarner
Former Employee

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

40ff4f84f634651f8c841dcf1137f47fcf9aed82.jpg

Copy the Bearer Token and URL for use the newly created task:
00924aae34579ff3087426d29d1752aa3da5886f.jpg

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

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

2bd91a27cd39391fa1f50005592b20dfa504a9da.jpg

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

0ddcb1f58c2e674c208475ee81f3d8b6278659d3.jpg

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

6bf5929d1fb031307a7f658879af8d000a9a12be.jpg

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

084f27b5f6af8320706e853dff69804c14f0761d.jpg

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.
010533399cd1ae1e88e00bacee42b54efc752903.jpg

Here is a dashboard view of the pipeline execution:
2695589c3e3fc86223da0c10eb961284634b0d1b.jpg

And the file created in the middle SNOW Query Path:
8c05b88fac836ffac2261595c300493c3e51f42e.jpg

0 REPLIES 0