
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-22-2020 08:00 AM
I hope this video helps a lot to all the beginners who want to Integrate ServiceNow instances or any other third party tool with their ServiceNow Instance.
If you like my post then please mark it helpful. Also if you have any questions then comment below.
Thanks and Regards:
Utpal Dutta
- 24,697 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
I tried what you said but I am not getting there sys id in my instance.
I have used below script. Can you check it and correct me where I am wrong
(function executeRule(current, previous /*null when async*/) {
var body={
"short_description":current.short_description.toString(),
"description": current.description.toString(),
"caller_id":current.getDisplayValue('caller_id'),
"state":current.getDisplayValue('state')
};
try {
var r = new sn_ws.RESTMessageV2('SN to SN', 'Incident post');
r.setStringParameterNoEscape('short desc', current.short_description);
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
gs.log("Response from instance = "+response);
var responseBody = response.getBody();
var json=responseBody;
var obj=JSON.parse(json);
var incidentSysId=obj.result.sys_id;
current.correlation_id=incidentSysId;
current.update();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
})(current, previous);

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Peter,
Which sys_id are you talking about? If you're talking about correlation id on incident form then by default it is hidden. You need to configure form layout and add Correlation ID field on your form.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
I have two instances A and B.
I am creating incident from A to B and it is working fine but I am not getting sys id of created incident from B to A.
And about correlation ID I have that field on form in both instances.
Thanks,
Peter.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Try adding:
gs.log("2nd instance id is"+incidentSysId);
After current.update(); and check in all logs if you're getting the sys_id or not
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
In logs I am getting sys id and also crosschecked and it is correct but only problem is it is not getting set in correlation id field.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Peter,
Why is doestn't work because from instance B to A there is a Staging table in between. Check the video once again. When we create a Web Service we do not let data enter in our system directly. We first put data in an staging table and then we map staging table fields to our Incident table.
That's why the above code for correlation ID doesn't work because data is not inserting directly in Incident table.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Peter,
For setting the correlation id you need to create a staging table field called correlation_id and then map it to incident table correlation id.
Hope above answer helps.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Try this business rue Peter after creating Correlation ID field in staging table and create new web service transform map where you need to map the fields again.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Web service and transform map (UPDATED)

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
After doing all this you will be able to see the SYS_ID of Instance B in your instance A incident.
If my answer helped then please mark it Helpful.
Thanks:
Utpal
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
still no luck,
I saw your video again, and at starting you created one incident with test pablo short description.After saving that incident you got value in correlation id field but in my case i am not able to get that ID. How could I get that?
Check your video screenshot below.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
I tried same what you have suggested still no luck.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you so much! So much content density here. I will try this Utpal! 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
i have tried this, but duplicates are getting created, any solution ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How we can achieve the
Correlation_id
felid display (incident number) in 2 instances vise Varsha please give step by step?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Uptal,
Can we do this for RITMs as well ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, I have "Creator User" account , I am unable to create System Admin account on serviceNow . How can I integrate APIs?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Peter,
It works for me. You will have to use this code in the Business rule while creating incident.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Hari,
Please check for any business rule which you have already created.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Utpal,
I have a ServiceNow to ServiceNow integration that needs to create and update a ticket. From our end, we will create an Incident, and then it will create a ticket from the other ServiceNow instance but in a custom table (Not Incident).
That is successfully working. However, when they are trying to update the ticket from their end (the target instance with custom table) like adding work notes to their ticket, the incident created from our end is not getting updated but instead, It is creating a new incident.
What should I do to get the update from the other ServiceNow ticket? I'm not sure why it is not getting updated, because I think it should be covered by the Business Rule and the REST Message I created. I already have the POST, and PUT methods.
Should I fix it on my end or it should be from the other instance that updates the ticket?
How will they update the ticket without creating a new one?
Your help will be much appreciated. Thanks in advance!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
When you make the call to the other environment, you should be able to parse the response body and set the correlation ID field to a value in the body.
Example snippet:
response = r.execute();
responseBody = response.getBody();
httpStatus = response.getStatusCode();
var obj = JSON.parse(responseBody);
var corrID = obj.result.<SOME VALUE>;
current.correlation_id = corrID;
gs.addInfoMessage('Correlation ID Set: ' + corrID);
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
how to pass attachments ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi, I just tried getting the Correlation ID populated from my target into the source instance and still not working. I am using the import/staging table scenario and below is my PUT BR. POST method works as expected and I'm able to see the Source INC Sys_ID populating the correlation id field in Target Instance.
Any idea on what's missing here?
function executeRule(current, previous /*null when async*/) {
var body = {
"state": current.getDisplayValue('state'),
"urgency": current.getDisplayValue('urgency'),
"impact": current.getDisplayValue('impact'),
"category": current.getValue('category'),
"subcategory": current.getValue('subcategory'),
"caller_id": current.getDisplayValue('caller_id'),
"short_description": current.short_description.toString(),
"description": current.description.toString(),
"configuration_item" : current.getDisplayValue('cmdb_ci'),
};
var CorID = current.getValue('correlation_id');
try {
var r = new sn_ws.RESTMessageV2('Incident Outbound to xxxxx', 'PUT');
r.setEndpoint('https://xxxxxqa.service-now.com/api/now/table/incident/'+CorID);
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
I have tried all instructions but still not able to see the correlation id of target instance to show in source instance. I have the ID for the source showing in the target instance though and using the staging table in target instance with all mappings done correctly.
Could it be my POST BR?
var body = {
"u_state": current.getDisplayValue('state'),
"u_urgency": current.getDisplayValue('urgency'),
"u_impact": current.getDisplayValue('impact'),
"u_category": current.getValue('category'),
"u_subcategory": current.getValue('subcategory'),
"u_caller_id": current.getDisplayValue('caller_id'),
"u_contact_type" : current.getDisplayValue('contact_type'),
"u_short_description": current.short_description.toString(),
"u_description": current.description.toString(),
"u_assignment_group" : current.getDisplayValue('assignment_group'),
"u_affected_user" :current.getDisplayValue('u_affected_user'),
"u_configuration_item" : current.getDisplayValue('cmdb_ci'),
"u_correlation_id" : current.getUniqueValue()
};
try {
var r = new sn_ws.RESTMessageV2('Incident Outbound to Me', 'POST');
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var obj = JSON.parse(responseBody);
var CorID = current.getValue('correlation_id');
}
catch(ex) {
var message = ex.message;
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Joshua
Can you share your PUT and POST BR please? Still dealing with the missing correlation ID from the target instance?
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Jehiellb,
Could you please help me understand more on the integration that was performed between 2 ServiceNow instances?
I am looking for integration between HI Incidents to our SN Incidents.
Thank you in Advance.
Thanks,
Yamuna
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi there,
Did you get a response to this question?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
Did you get the Answer for this Question...?
Iam also Facing the Same issue can you suggest the solution..
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Peter,
kindly add an underscore in below for short_desc and recheck
r.setStringParameterNoEscape('short desc', current.short_description);
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
I implemented the each and every business rules in 2 Snow instances as you said in the video, but for me a recursion is happening means when we updating the incident in any instance, then infinite times are getting updating in both instances. What is the problem you think?
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I implemented the each and every business rules in 2 Snow instances as you said in the video, but for me a recursion is happening means when we updating the incident in any instance, then infinite times are getting updating in both instances. What is the problem you think?
Thanks
Regards
Raju Manga
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I implemented the each and every business rules in 2 Snow instances as you said in the video, but for me a recursion is happening means when we creating the incident in target instance, then infinite times records are getting in both instances. What is the problem you think? what conditioni need put in business rule.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have similar issue,
We are doing E-bonding b/w X & Y companies.
X company is passing Incident data & it's flowing as expected & creating ticket on Y company Incident table with information passed.
I want to receive the ticket number created on Y company on correlation ID field of X company, to confirm that ticket is created.
I have done below stuff but not receiving it. Not sure what is missed.
Please guide me
Scripted REST API
Script Include
ebondIncidentUpdate: function() {
var requestBody = request.body;
var requestData = requestBody.data;
//u_partner_ticket_id is the Y company field to store number (Ex:- Incident number).
if (requestData.u_partner_ticket_id == undefined || requestData.u_partner_ticket_id == '') {
response.setError(new sn_ws_err.BadRequestError('Correlation ID is missing'));
return;
}
if (requestData.number == undefined || requestData.number == '') {
response.setError(new sn_ws_err.BadRequestError('Number is missing'));
return;
}
var gr = new GlideRecord('incident');
gr.addQuery('number', requestData.number);
gr.query();
if (gr.next()) {
gr.correlation_id = requestData.u_partner_ticket_id;
gr.update();
} else {
response.setError(new sn_ws_err.BadRequestError('Incident not found'));
return;
}
// start building response object
response.setStatus(200);
response.setContentType('application/json');
var body = {
status: 'ok',
requesterId: gr.number,
providerId: gr.correlation_id,
sys_id: gr.getUniqueValue()
};
response.setBody(body);
},
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Naveen,
In Business rule try to add the below code in X instance after the line
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Sharing this tutorial to complement the article that demonstrates good coding practices like object oriented programming, service oriented architecture, global logging techniques, SOLID design patterns. Implementing a fully reliable, scalable and reusable code.
How to Call Third Party REST API Integrations in ServiceNow Using GlideAjax & Script Includes
Dynamic Script Include and GlideAjax in ServiceNow: Scalable & Reusable Code for Architects