Sending a REST Message with no REST Message Record for incident records

arulvelu
Kilo Contributor

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

12 REPLIES 12

is it possible to get the current event records ( incident information) . How can we get the details , through which object ?


hi ,


This article will help you.




Mini-Lab: Extending the GlideRecord Object



Thanks


- YLN


otog
Tera Contributor

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.