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 04:34 AM
Thanks for your continued support.
After adding the above mentioned lines related to comments , But still we're getting the same error.
Advance thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 05:20 AM
can you add log for this and share how the request body looks like
(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, '');
gs.info('notes is' + notes);
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.info('Request body is' + r.getRequestBody()); // check this
gs.log("This is update incident result: " + responseBody);
var httpStatus = response.getStatusCode();
gs.log("Status of the update incident:" + httpStatus);
})(current, previous);
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 05:30 AM
Hi Ankur,
Thanks for the update.
Entered work notes are not showing on logs level but it's not passing to target instance.
Please find the below logs steps:
Notes logs:
Advance thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 06:28 AM
it seems work notes has data and is included correctly in the request body but has new line character
try to remove that and test once
Also try to use POST method instead of PATCH
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
notes = notes.replace(dateRE, '');
notes = notes.replace('\n',"");
gs.info('notes is' + notes);
r.setStringParameterNoEscape('comments', notes); // this will just includet the text and remove the date timestamp etc
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 06:42 AM
Hi Ankur,
Tried your suggestions. But now logs level notes coming as empty and also tried with post method same notes coming as blanck.
pls check Script once:
Advance thanks.