Integration
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2024 03:38 AM
Hello Team,
I make a post method to create one incident instance a and it will create same incident in instance b.
I need a help how to populate sysid field from Instance b to instance a correlation id field after creating incident in both of that instace.
this is instance b sysid
this instance a correlation id where we need to fetch data
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 02:24 PM
Hi, when you post/insert a record, JSON of the record is normally returned in the result and you can extract the new records sys_id from the response payload.
Using script generated from REST API explorer you can extract sys_id like this
//REST API explorer sample script.
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://yourInstance.service-now.com/api/now/table/incident');
request.setHttpMethod('POST');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"short_description\":\"a test incident\"}");
var response = request.execute();
// Now parse the response to JSON
var responseBody = JSON.parse(response.getBody());
//logging this to screen, just so you can see if the test transaction is successful
gs.info(JSON.stringify(responseBody));
//Now walk to the new records sys_id
var myNewSysId = responseBody.result.sys_id;
gs.info('records sys_id ' + myNewSysId );