Sending a REST Message with no REST Message Record for incident records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2017 06:04 AM
Hi Folks , I have written this script to check for active incidents that had happened few minutes ago and send this details to 3rd party rest api ( node server written by me) .
sendNewIncidents();
function sendNewIncidents() {
var d = new Date();
var gr = new GlideRecord('incident');
gr.addQuery('priority',1);
gr.addQuery('impact',1);
gr.addQuery('active',true);
gr.addQuery('sys_created_on','>=', gs.minutesAgo(560));
gr.query();
var incident = {};
var incidentList = [];
while (gr.next()) {
incident = {};
gs.addInfoMessage(gr.number);
gs.addInfoMessage(gr.short_description);
gs.addInfoMessage(gr.category);
gs.addInfoMessage(gr.cmdb_ci);
incident.number = gr.number + '';
incident.cmdb_ci = gr.cmdb_ci.value + '';
incident.desc = gr.short_description +'';
incident.openTime = gr.opened_at + '';
incident.category = gr.category+ '';
incidentList.push(incident);
}
gs.log("Lenght is:"+incidentList.length);
for(i=0;i<incidentList.length;i++) {
var incidentDetails = incidentList[i];
gs.log (JSON.stringify(incidentDetails));
var dataSend = JSON.stringify(incidentDetails);
var stringData= new global.JSON().encode(dataSend);
gs.log(stringData);
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("post");
restMessage.setEndpoint("http://12.12.14.25/incident/");
restMessage.setRequestBody(stringData);
var response = restMessage.executeAsync();
gs.log(JSON.stringify(response));
}
}
I am creating a restmessage with no message record in the forloop and posting it to my http endpoint "http://12.12.14.25/incident/" and doing this in async way. When i execute this script, i am debugging the response in node server where i get only { } . This as result. Please let me know where i have gone wrong. Thanks Arul
Message was edited by: Arulvelu Gunasekaran
Message was edited by: Arulvelu Gunasekaran
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2017 11:11 PM
is it possible to get the current event records ( incident information) . How can we get the details , through which object ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2017 06:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2018 09:08 AM
Hi,
I would suggest you to declare a variable other than 'i' as it is being extensively used internally within servicenow scripts try something like this - "for(var count=0;count<5; count++)".
Thanks.