REST API - Patch and PUT methods to update multiple incident tickets.

LaraReddy
Tera Guru

Hi All,
We're integrated two servicenow instances to create the incident tickets when ever an incident ticket is created in one instance we need to replicate the same in another instance.
And we have used REST API - POST method and it's working fine now.

But we want to update the incident when ever we update the incidents in one instance need to set the same field info in another instance.

We're trying to use REST API  "PUT / Patch" methods, but it's not updating in another instance.

Note: It's working properly only when we give the ticket sys_id in endpoint.

But we have more than one incident tickets and we need to update only mirror incident ticket in another instance.

And sys_id are same in both the tickets on instance level.


Advance thanks.

22 REPLIES 22

Hi Ankur,
Many thanks for the update.

After giving below URL as endpoint, we're getting attached error.

endpoint: https://devXXXXX.service-now.com/api/now/table/incident/ + current.sys_id

 

LaraReddy_1-1688722959695.png

 

Could you pls help us here.

Advance thanks.

 

@LaraReddy 

got it

when you are hitting target instance then are you storing the target incident record sysId in some field on current incident i.e. are you storing it in correlation_id field

Unless you know the target record sysId you cannot update

And sys_id are same in both the tickets on instance level. -> this is wrong the sysIds would be different. Did you check both the incidents?

try to update as this if you are using correlation_id field

r.setEndpoint('https://dev75096.service-now.com/api/now/table/incident/' + current.correlation_id);

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,
I have checked the created incidents sys_id'S on both the instances level and having same sys_id'S.

Do we need to make any changes on BR script level.

Advance thanks.

 

 

@LaraReddy 

if that's the case then the endpoint should be a valid one

I think you didn't copy the exact script I shared. you are using an extra quote it seems

share your updated script

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,
Thanks for your valuable time.

PLease find the below script: BR -> After -> Update

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

var r = new sn_ws.RESTMessageV2('CR instance', 'Update Incident');
r.setEndpoint('https://dev1209.service-now.com/api/now/table/incident/' + current.sys_id);
r.setStringParameterNoEscape('group',current.assignment_group);
r.setStringParameterNoEscape('toPerson', current.assigned_to);
r.setStringParameterNoEscape('state',current.state);
r.setStringParameterNoEscape('callerDetails',current.caller_id);
r.setStringParameterNoEscape('comments', current.work_notes);
r.setStringParameterNoEscape('shortDesc', current.short_description);
//r.setStringParameterNoEscape('id',current.sys_id);

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

gs.log("This is update incident result: " + responseBody);
var httpStatus = response.getStatusCode();

gs.log("Status of the update incident:" + httpStatus);
})(current, previous);

Note: Logs level we're getting as below:
Status of the update incident:405


And if we use patch method and clicks on test link, we're getting below error as well:

LaraReddy_1-1688725880155.png

 


 



Advance thanks.