REST API - Patch and PUT methods to update multiple incident tickets.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 01:10 AM - edited ‎07-07-2023 01:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 03:36 AM
don't use test link; it won't work as there is no reference for current object.
please update actual record in source and let BR run and then verify in target
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 03:49 AM
HI Ankur,
Thanks for the response.
It's working fine but the work notes are not moving to target instance.
Even though we got mentioned on BR level.
Advance thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 04:04 AM
Glad to know that it worked
for that you need to fetch latest work notes like this
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 04:11 AM
HI Ankur,
If we add the above the line, then status of code on logs level coming as :
This is update incident result: {"error":{"message":"Exception while reading request","detail":"The payload is not valid JSON."},"status":"failure"}
Advance thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 04:29 AM
then do this
(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);
var notes = current.work_notes.getJournalEntry(1); // get the latest work notes
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
notes = notes.replace(dateRE, '');
r.setStringParameterNoEscape('comments', notes); // this will just includet the text and remove the date timestamp etc
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);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader