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