How to send the state and comment change update values of incident in a JSON format in integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2025 03:52 AM
Hi All,
I am working on a integration where when an incident is created in third party incident to be created in servicenow. This i was able to achieve. Now when state changes or any comments is added in an incident that value i need to send to external system in json format. Please guide me to achieve this functionality.
{
incidentnumber:"",
state:"",
comments:"",
externalid:""
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2025 05:24 AM
You can create a after business rule on update and write the following script to get the data and convert into JSON.
var returnObj = {};
returnObj.incidentnumber = current.number;
returnObj.state = current.state;
returnObj.comments = current.comments;
returnObj.externalid = current.external_id;
//Invoke the Integration method and use the above defined object as body of the message to be sent to external
Mark the answer as correct and helpful if it resolves your issue. Happy Scripting 🙂
-Shantanu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2025 05:37 AM
how did you configure this endpoint?
You can use Flow designer REST Step to form the json object and consume the endpoint
check this
Outbound REST integration using flow designer
OR
you can use after update business rule on incident table and condition
State Changes OR Comments Changes
Script: This is just an example, we don't know what type of Authentication you are using if it's Basic/OAuth etc
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('Endpoint');
//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.setHttpMethod('POST');
var body = {
incidentnumber: current.getValue('number'),
state: current.state.getDisplayValue(),
comments: current.comments.getJournalEntry(1),
externalid: current.correlation_id.toString()
};
request.setRequestBody(JSON.stringify(body));
var response = request.execute();
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
‎05-14-2025 12:33 AM
Thanks Ankur, Above script worked.I am planning to use oauth2.0 authentication, How so i set this authentication in above script.