Update Incident - REST API

Palacharla Gowt
Tera Contributor

Using REST Message POST Method, I'm able to create an incident in another instance of ServiceNow using after-insert business rule. I need help with update of the incident i.e., if someone updates that incident from their end, I want it to be updated on my instance. I need help with the business rule script for the update of it. Please help me how to achieve this?

 

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

Hi you can use REST API explored like below to build the script

 

HarishKM_0-1696298066347.png

 

and

 

Here is the example. You need to create PUT method REST API.

// pass fields to update

var obj = {
"close_code": current.getValue('close_code'),
"close_notes": current.getValue('close_notes'),
"state": current.getValue('state')
};
var id = current.correlation_id; // sysid of incident of other instance
try {
var r = new sn_ws.RESTMessageV2('IncidentCreation', 'updateINC'); // Rest Message name and Put Method API name
r.setEndpoint("https://xxx.service-now.com/api/now/table/incident/" + id); // end point
r.setHttpMethod(PUT);
r.setRequestBody(JSON.stringify(obj));
var response = r.execute();
var responseBody = response.getBody();
gs.info("Request Body==>" + JSON.stringify(responseBody));
var httpStatus = response.getStatusCode();
gs.info("httpStatus==>" + httpStatus);
} catch (ex) {
var message = ex.message;
}

Regards
Harish

AnveshKumar M
Tera Sage
Tera Sage

Hello @Palacharla Gowt 

Are you using a Scripted REST API or OOTB Table API.

 

You can use REST API Explorer to generate code samples for both Scripted REST or Table API and you can use that in your BR to trigger the transaction.

 

And preferably use Async Business Rule to improve User experience.

 

Please let me know if you need any more help on this.

Thanks,
Anvesh

Ankur Bawiskar
Tera Patron
Tera Patron

@Palacharla Gowt 

Refer below links for step by step instructions on how to integrate 2 servicenow instances

ServiceNow to ServiceNow Integration using REST API and PUSH and PUT methods with Business Rule 

You can also explore on Ebonding Spoke with less scripting

ServiceNow eBonding spoke 

Refer the below link which has the approach with example shared by me.

Integration hub ebonding spoke 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader