Integration

Shrabanti Mukhe
Tera Contributor

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

ShrabantiMukhe_0-1720780371842.png
this instance a correlation id where we need to fetch data

ShrabantiMukhe_1-1720780479078.png

 

 



1 REPLY 1

Tony Chatfield1
Kilo Patron

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 );