- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 04:05 AM
Hi,
I'm trying to trigger a business rule to send out any work notes or additional comments to a 3rd party tool via outbound REST.
I have the outbound request created but I need to be able to get certain fields from the incident and include them in the JSON to send. For eg. I need the value of the "caller_id" so that I can update the original event in the 3rd party tool, similarly I would need the value for the work notes and the additional comments and create a JSON with them to be sent.
How can this be done?
I have created a static JSON in the "HTTP Query Parameters" section of the outbound REST message and was able to successfully test it.
I have also created the Business rule to be triggered and defined the "When to Run" conditions correctly, I have also defined a basic advanced script to call the outbound REST message like so:
function onAfter(current, previous)
{
var r;
var response;
var responseBody;
var httpStatus;
var message;
try {
r = new sn_ws.RESTMessageV2('Incident Notes Send', 'put');
response = r.execute();
responseBody = response.getBody();
httpStatus = response.getStatusCode();
}
catch(ex) {
message = ex.getMessage();
}
gs.log("Content: " + current.work_notes.getJournalEntry(1));
gs.log("Request Body: " + response);
gs.log("Response: " + responseBody);
gs.log("HTTP Status: " + httpStatus);
gs.log("Error Message:" + message);
}
But I'm not sure how to pass variable from here to the REST request.
Also as I understand I should see the "gs.log()" entries in the debug business rules but I see only that the business rule was triggered.
I'm very new to ServiceNow and any help from the gurus would be much appreciated.
Regards,
Karan
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 02:11 AM
Hello,
Thanks for all the help. I was finally able to solve this.
It turned out that the request I was sending was generating errors on the other side due to the format.
The final version of the javascript was :
try {
var r = new sn_ws.RESTMessageV2('Incident Notes to event', 'put');
var notes = current.work_notes.getJournalEntry(1);
notes=notes.replace(/["']/g, "");
notes=notes.replace(/[\n*]/g, " ");
notes = String(notes);
var id = String(current.u_eventid).replace(/["']/g, "");
r.setStringParameter("id",id);
r.setStringParameter("notes",notes);
r.setRequestHeader("Accept","application/json");
r.setRequestHeader('Content-Type','application/json');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage("Response Body:" + responseBody);
gs.addInfoMessage("Response status:" + httpStatus);
}
catch(ex) {
var message = ex.getMessage();
}
Thanks again for the help in getting this work!
Regards,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 02:44 AM
In Which table you have written this business rule??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 02:46 AM
The business rule is in Incident [Incident] table.
Regards,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 05:53 AM
The Journal fields are stored in sys_journal_field. So you have to update in this table.
Check the Rest endpoint. The endpoint should be at sys_journal_field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 02:11 AM
Hello,
Thanks for all the help. I was finally able to solve this.
It turned out that the request I was sending was generating errors on the other side due to the format.
The final version of the javascript was :
try {
var r = new sn_ws.RESTMessageV2('Incident Notes to event', 'put');
var notes = current.work_notes.getJournalEntry(1);
notes=notes.replace(/["']/g, "");
notes=notes.replace(/[\n*]/g, " ");
notes = String(notes);
var id = String(current.u_eventid).replace(/["']/g, "");
r.setStringParameter("id",id);
r.setStringParameter("notes",notes);
r.setRequestHeader("Accept","application/json");
r.setRequestHeader('Content-Type','application/json');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage("Response Body:" + responseBody);
gs.addInfoMessage("Response status:" + httpStatus);
}
catch(ex) {
var message = ex.getMessage();
}
Thanks again for the help in getting this work!
Regards,
Karan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2019 02:18 AM
Hello Karan,
I am also getting the same issue.
Could you please confirm if you have created a BR on Incident table of Sys_journal_fied table
And what is u_eventid in this script.
Thanks,
Priyanka