REST API Integration not working while using the PUT method to update incident on another SNOW instance

suhan07
Kilo Contributor

Hi, 

I am new to REST API Integration, still exploring the ServiceNow learning curve. I am trying to implement an eBonding integration between two SN instances - SN1 (source) and SN2 (target). 

I am able to successfully create the incident. However, when I am trying to update the incident using the "PUT" method, any update in SN1 is not being reflected in SN2. For your reference, I am providing the BR below, would really appreciate some help here?

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

// Add your code here

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

var corID = current.getValue('correlation_id');

try {
var r = new sn_ws.RESTMessageV2('TDC Integration', 'Default PUT');
r.setEndpoint('https://dev100277.service-now.com/api/now/table/incident/'+corID);
r.setRequestBody(JSON.stringify(body));

//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

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

   

 

17 REPLIES 17

sachin_namjoshi
Kilo Patron
Kilo Patron

There is a OOB integration hub spoke available to integrate 2 servicenow instances.

 

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/integrationhub/refere...

 

As far as your issue is mentioned, you should use REST API explorer to generate sample payload and use code generated by platform like below

 

 

find_real_file.png

 

Regards,

Sachin

 

Thank you Sachin.

But, how do I know the sys_id of the incident created in the target instance, so that I can pass that in the url through setEndpoint?

Chuck Tomasi
Tera Patron

You might want to look in to using Instance Data Replication (IDR) for this. It's designed specifically for ServiceNow-ServiceNow data copying. It even supports bi-directional. Very easy to configure compared to creating your own scripts and business rules. It comes down to "buy vs build". In this case, I have found extreme value in simply configuring a couple records and data is kept in sync in real-time. It's very scalable too so if you need to add a second or third instance, it's just a matter of subscribing a producer to the consumer.

After writing more than my fair share of REST APIs, I'll can appreciate the development and maintenance cost savings of IDR.

Thank you Chuck. Will keep this mind.

 

But at this point, my org wants to explore the ServiceNow ebonding spoke functionality; and I am not sure why my update action is not working at all. 

 

Any help would be greatly appreciated.

I'm confused. Are you creating an action or are you using an outbound REST message script? The two don't really go together. Your original question had a script in it. If you're writing your own spoke, then there should be very little script involved (because you want to use the REST Step in your spoke's action.)

Please clarify.