How to access current object in business rule script when incident is inserted

arulvelu
Kilo Contributor

Hi , My requirement is when a new incident is inserted . I need to access this new incident details and get information such as cmdb_ci, short_description,comments etc and send this to REST API. Please find my below code which i have written in buisness rule script actions part

if (current.operation() =='insert') {

var incidentDetail= [];

var incident = {};

gs.addInfoMessage('incident information is inserted');

gs.eventQueue('incident.inserted',current);

gs.log(current);

incident.cmdb_ci = current.cmdb_ci + '';

incident.short_description = current.short_description + '';

incidentDetail.push(incident);

var dataSend =   JSON.stringify(incidentDetail);

var stringData= new global.JSON().encode(dataSend);

var restMessage =   new sn_ws.RESTMessageV2();

restMessage.setHttpMethod("post");

restMessage.setRequestHeader("Content-Type","text/plain");

restMessage.setEndpoint("http://34.229.73.40/incident/");

restMessage.setRequestBody(stringData);

gs.addInfoMessage('Before sending a rest message'+restMessage);

var response = restMessage.executeAsync();

}

This configured in way when an insert to database happens. I dont know how to debug this details and can can someone clearly explain how this buisness rule works. Please correct my code if anything needs to be changed Thanks Arul

Message was edited by: Arulvelu Gunasekaran

Message was edited by: Arulvelu Gunasekaran

Message was edited by: Arulvelu Gunasekaran

5 REPLIES 5

Hi,



Can you please share the value which you receive when you log the response.



Please add a gs.log(response, "Response") at the end of the code and share the result