Utpal Dutta1
Mega Guru

 

 

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

Comments
Peter Wood
Kilo Guru

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);

Utpal Dutta1
Mega Guru

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.

Peter Wood
Kilo Guru

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.

Utpal Dutta1
Mega Guru

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

Peter Wood
Kilo Guru

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.

Utpal Dutta1
Mega Guru

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.

Utpal Dutta1
Mega Guru

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. 

Utpal Dutta1
Mega Guru

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.

 

find_real_file.png

Utpal Dutta1
Mega Guru

Web service and transform map (UPDATED)

 

find_real_file.png

 

 

find_real_file.png

Utpal Dutta1
Mega Guru

After doing all this you will be able to see the SYS_ID of Instance B in your instance A incident.

 

find_real_file.png 

If my answer helped then please mark it Helpful.

 

Thanks:

Utpal

Peter Wood
Kilo Guru

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.

find_real_file.png

Peter Wood
Kilo Guru

Hi,

I tried same what you have suggested still no luck.

stb2
Kilo Contributor

Thank you so much! So much content density here. I will try this Utpal! 🙂

Inactive_Us1589
Kilo Contributor

i have tried this, but duplicates are getting created, any solution ?

Mahesh130
Tera Contributor

How we can achieve the

Correlation_id 

felid display (incident number) in 2 instances vise Varsha please give step by step? 

Joshuu
Kilo Sage

Hello Uptal,

Can we do this for RITMs as well ?

Rishma
Kilo Contributor

Hi, I have "Creator User" account , I am unable to create System Admin account on serviceNow . How can I integrate APIs?

RWHeals
Tera Contributor

Thank you!

joshuastanley
Tera Expert

Hello Peter, 

It works for me. You will have to use this code in the Business rule while creating incident.

joshuastanley
Tera Expert

Hi Hari,

Please check for any business rule which you have already created.

Jehiellb
Giga Contributor

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!

AJugovic
Tera Expert

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);

rohit198881
Kilo Contributor

how to pass attachments ?

Sege1
Kilo Explorer

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;
}

Sege1
Kilo Explorer

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;
}

Sege1
Kilo Explorer

Hello Joshua

 

Can you share your PUT and POST BR please? Still dealing with the missing correlation ID from the target instance?

Thanks

Yamuna2
Tera Contributor

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

 

 

Hola Ola
Giga Guru

Hi there, 

Did you get a response to this question?

vijay131
Tera Contributor

@Utpal Dutta I have seen your complete video, I need really a quick help from you Its bit urgent as your video does not have this..I dont see If incident is updated in Pablo, how to update the incident in Felix using import set table API provided by Felix. 

 

Sivaram5
Tera Contributor

Hi 

Jehiellb

 Did you get the Answer for this Question...? 

Iam also Facing the Same issue can you suggest the solution..

 

Thanks

Pooja Joshi1
Tera Contributor

Hi Peter,

 

kindly add an underscore in below for short_desc and recheck

 

r.setStringParameterNoEscape('short desc', current.short_description);

Raju manga13
Giga Explorer

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

RAJU MANGA
Tera Contributor

Hi @Utpal Dutta1 

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

venugopal1999
Tera Explorer

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.

Naveen87
Tera Guru

@Utpal Dutta1 ,

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

Naveen87_0-1711022304095.png

Scripted REST API

Naveen87_1-1711022337328.png

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);
    },

 

venugopal1999
Tera Explorer

@Naveen87 

Hi Naveen, 

In Business rule try to add the below code in X instance after the line 

 [ var responseBody = response.getBody(); ]
        var obj = JSON.parse(responseBody);
        var foundSysId = obj.result.sys_id; /* Here  Y instance sys_id  is stored ,you can replace it with  ticket number  ( Ex: obj.result.number)*/
        current.correlation_id = foundSysId; 
        current.update();// if you are using after insert business rule then use current.update().

 

 

BillMartin
Mega Sage

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

 

Version history
Last update:
‎05-22-2020 08:00 AM
Updated by: