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 02:04 AM
Hello,
Its working as expected, if you use the direct webservice available ootb on incident table you will need to pass sys_id of incident of target instance.
if you want to use anything else lets say, 'number' you will need to create your custom scripted rest api with put/patch method and by making use of gliderecord, identify the record and update it.
Hope this helps
Thanks
Harshad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 02:11 AM
if you are using OOB table API then you would require sysId only of the target incident record
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 02:23 AM
Hi Both,
Thanks for the response.
PLease find the below steps what we're currently following on to update the target instance record.
Step1:
Step 2:
Step 3:
Business RUle -> Before - Update -> INC table level
Script:
Apart for these steps we're not doing any additional steps.
SInce we're completely new to integrations, could you pls guide us how to update the target instance records.
Note: Through this steps we're able to update the target instance INC record only one because of the same record sys_id got mentioned on end point level.
Advance thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2023 02:32 AM - edited ‎07-07-2023 02:32 AM
make the BR as after update
this BR will run on every record update so don't hard-code the record sysId
Instead use variable substitution and replace the sysId with the actual record sysid
OR
set the endpoint dynamically from script and remove the endpoint used in PATCH method
I would suggest 2nd way as it's easier
sharing sample script for that
(function executeRule(current, previous /*null when async*/) {
var r = new sn_ws.RESTMessageV2('CR instance', 'Update Incident');
r.setEndpoint('https://dev75096.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);
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