Snow To Snow Bidirectional Integration - DxSherpa

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

7/6/22, 7:56 PM Snow to Snow Bidirectional Integration | DxSherpa

SNOW To SNOW Bidirectional Integration (REST)


What is Integration?

Using Integration Two Different or Same Platform /Tool / Application Can communicate with each
other, they can able to Post Data, Get Data, Update Data, Delete Data between them using REST HTTP
Methods

What is Bi-Directional Integration?

Bi-Direction Integration means both the App can able Performed Operations on each other; basically
we can say it’s a two way communication.

What is Uni-Directional Integration?

Uni-Direction Integration means only one app can able Performed Operations on another App; it’s a
One way communication.

What are the REST HTTP Method in ServiceNow?[CRUD]

GET : Use for fetching data from another application


POST: Use for create record in another application
PUT: Use for Update record in another application
PATCH : Use for Update record Partially in another application
DELETE : Use for Delete record

Types of Integration

Outbound Integration :- ServiceNow can Performed CRUD Operation in Third Party Tool
Inbound Integration :- Third-party Tool can Performed CRUD Operation in ServiceNow

POST METHOD :- Both instance can able to POST data between each other

Steps:

1) Create Outbound REST Message

[Application Navigator -> System Web Service ->Outbound REST Message]

Thing Required for Outbound REST


https://dxsherpa.com/blogs/snow-to-snow-bidirectional-integration/ 1/6
7/6/22, 7:56 PM Snow to Snow Bidirectional Integration | DxSherpa

*Endpoint: URL of the API of Another system

Example: – https://dev2522.service-now.com/api/now/table/incident (you will get this in another instance


of SNOW in REST API Explorer)

*Http Headers: It is a Response format which is getting from another instance

*Authentication: It is an Credential [Userid , Password] of third party Instance

You can create it by clicking on magnifier glass new-> give Name /Userid/Password of another instance

*HTTP Methods: – Add Method as per Operation Requirement


https://dxsherpa.com/blogs/snow-to-snow-bidirectional-integration/ 2/6
7/6/22, 7:56 PM Snow to Snow Bidirectional Integration | DxSherpa

Click on New:-

Name: – Give any Name [ex POST]

HTTP Method: – POST [you can select as per your requirement]

Endpoint: – Pest endpoint of Third party API

HTTP Headers: – add Headers [Accept / content type]

Save – and Click on Test in related links to check connection

If you get 201 as status means tested successfully and will get expected response.

Click on related link Preview Script Usage from HTTP Method page.

Preview Script Usage: – It is Automated created Script for our Outbound REST message, we can use this
Script in Business Rule for Connecting Current Instance to another instance,

If we use this Script in Business Rule then we don’t need to add [Endpoint/HtppMethod/Basic
Authentication/Http Headers] in Business Rule as Preview Script Usage contains all this Things.

https://dxsherpa.com/blogs/snow-to-snow-bidirectional-integration/ 3/6
7/6/22, 7:56 PM Snow to Snow Bidirectional Integration | DxSherpa

So as our Outbound REST Message is tested successfully then we can good to create Business Rule for
Posting Data through Current instance to another instance.

2) Create Business Rule

We can Use After/Sync – insert for Posting data

In Business Rule first we need to Store Payload body structure of another instance in variable so that
Data can map correctly.
Then we need to add Script which is taken from Outbound REST Message
Here our body structure is in JSON format so we need to convert it in String so ServiceNow can Read .
to do this we used [r.setRequestBody(JSON.stringify(body));]
Also the Response we are getting is in JSON Format so again we need to parse it var ParseData =
JSON.parse(response.getBody()); only if we need to perform operations on response [ie PUT]

(function executeRule(current, previous /*null when async*/ ) {


var body = {
"short_description": current.short_description.toString(),
"urgency": current.urgency.toString(),
"caller_id": current.getDisplayValue('caller_id'),
"impact": current.getDisplayValue('impact'),
"state": current.getDisplayValue('state'),
"priority": current.getDisplayValue('priority'),
"subcategory": current.getDisplayValue('subcategory'),
"category": current.getDisplayValue('category'),
};

try {

var r = new sn_ws.RESTMessageV2('Snow-Bi', 'POST');


r.setRequestBody(JSON.stringify(body));

var response = r.execute();


current.insert();
var httpStatus = response.getStatusCode(); }

catch (ex) {

var message = ex.message; }


}) (current, previous);

Create New record in Current Instance you will get same incident in another instance

https://dxsherpa.com/blogs/snow-to-snow-bidirectional-integration/ 4/6
7/6/22, 7:56 PM Snow to Snow Bidirectional Integration | DxSherpa

Getting Data from another instance [B] to current instance [A] we need to Set Inbound
Web Service

You need to Follow above Steps in Another instance so Instance B also able to Post Data in instance A

We just need to pass sys_id for Instance B to A why ? It will use in PUT method Just add “u_externalsys_id” :
current.getValue(‘sys_id’), in body Payload And Create 1 field in Incident Form of Instance A[Target instance]
“External_Sys_id” Type :- String, This field store sys_id of instance B[Source instance]

PUT METHOD: – Both instance can able to update data between each other [for
instance A to B]

For Processing PUT method first thing we need to keep in mind that we are Performing Updation on Single
Record so we need its sys_id to work on. So in Endpoint we are not mentioning sys_id as it will different for
every record, hence we are passing sys_id of particular record Dynamically in Business Rule.

For updating data you need to create PUT method in Outbound REST Message In instance A [Source
instance] , as we have already created Outbound REST Message for POST, so we just need to add PUT
method in HTTP Method.

Create Business Rule [After-Update] in Instance A[Source Instance]

A] Add Body Structure whatever field we want to update.

B] Create 1 field in Incident Form “External_Sys_id” Type: – String, [ if you have not created in POST B to A ]
This field store sys_id of another instance record so we can add this sys_id in our Endpoint, so we can
modified that particular record

In Business Rule Script we need to fetch it and add it to Endpoint as we are passing sys_id dynamically var
Ex_sys = current.getValue(‘u_externalsys_id’);

C] Then we need to add Script which is taken from Outbound REST Message.

(function executeRule(current, previous /*null when async*/ ) {


var body = {
https://dxsherpa.com/blogs/snow-to-snow-bidirectional-integration/ 5/6
7/6/22, 7:56 PM Snow to Snow Bidirectional Integration | DxSherpa

"short_description": current.short_description.toString(),
"urgency": current.urgency.toString(),
"caller_id": current.getDisplayValue('caller_id'),
"impact": current.getDisplayValue('impact'),
"state": current.getDisplayValue('state'),
"priority": current.getDisplayValue('priority'),
"subcategory": current.getDisplayValue('subcategory'),
"category": current.getDisplayValue('category'),
};

var Ex_sys = current.getValue('u_externalsys_id');

try {
var r = new sn_ws.RESTMessageV2('Snow-Bi', 'PUT');
r.setEndpoint('https://dev62522.service-now.com/api/now/table/incident/' +
Ex_sys);
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

} catch (ex) {
var message = ex.message;
}
})(current, previous);

Save

Now Create 2-3 Record in instance B[Tareget Instance] and Check in you Source instance You will get same
Record with External sys_id , so When you will updating Record in Instance A[Source Instance] it will Update
in Instance B, through sys_id

https://dxsherpa.com/blogs/snow-to-snow-bidirectional-integration/ 6/6

You might also like