Professional Documents
Culture Documents
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();
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++) {
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
hi,
it is working without any problem.
gr.get('d71f7935c0a8016700802b64c67c11c6');
var str = JSON.stringify(gr);
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("post");
restMessage.setEndpoint("http://localhost:4000/incident");
restMessage.setRequestBody(str);
var response = restMessage.execute();
gs.addInfoMessage(JSON.stringify(response.getBody()));
node - server:
But if i use the "express" server , then i am getting empty response just like you said. Hope this
helps.
updated script:-
now script:-
gr.get('d71f7935c0a8016700802b64c67c11c6');
var str = JSON.stringify(gr);
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("post");
restMessage.setEndpoint("http://localhost:4000/incident");
restMessage.setRequestBody(str);
var response = restMessage.executeAsync();
response.waitForResponse(60);
gs.addInfoMessage(JSON.stringify(response.getBody()));
Thanks
-YLN
cool,
Please Hit ✅Correct, ⭐️Helpful, or ❣️Like depending on the impact of the response
Thanks
- YLN
lakshmi , what is the difference between buiness rule and script actions. If i need to test this
script ( currently i have tested this script in script debugger) How can i make it live in script
actions.
Hi ,
That depends on when you want to send this data node server. if you want send when record
changes , then BR is good.
Thanks
- YLN
Hi Lakshmi , sorry for bugging you.. I have a question to clarify. I want my node server to
subscribe incident.inserted events in my node server . Is there any option that service now
provides to send events via webhook. Regards Arul
So whenever you inserted a new incident record, that information (incident record ) should pass
to your node server. if that is the requirement, you can write a Business rule on incident table
and call RESTMessageV2.
Thanks
- YLN
is it possible to get the current event records ( incident information) . How can we get the details ,
through which object ?
This document was generated from the following discussion: Sending a REST Message with no
REST Message Record for incident records