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

saprem_d
Giga Guru

Hi,



You can add a log statement at the very start of the business rule to confirm it is executing and at the end to check if the response is being received



Just put a gs.log(response); before var response = var response = restMessage.executeAsync(); statement


Hi Saprem , Logging i have included already.. But when an incident is inserted i am not able to see this meesage in my server. Am i accessing the current object properly? Thanks Arul


Hi,



If you are able to see the response in the logs, Problem is not at ServiceNow


Hi Saprem , Can i have some thoughts on this ? Whether the logic which i have written is correct ?Please assist