Script Action not able to call outbound rest message even though the event is processed

Swarnarghya
Tera Expert

We have a business rule which is scheduling one event in the event queue. The script action will run once that event is processed. And  we have an event queue scheduled where we are processing the event after half an hour by using delay method in our business rule. The event is getting processed in the event logs but the script action is unable to call the outbound rest message.

find_real_file.png

Can you please help us why this is not working?

 

PS: Manual trigger of rest message is working fine

1 ACCEPTED SOLUTION

If your instance is domain separated then Script action should be in global domain.

So just add this line in your script action

gs.info('My script action triggered');

If this log doesn't come then the issue is not with script

Other solution

1) make your BR as Async update and add the entire REST Message code inside BR

That should work fine

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

18 REPLIES 18

gs.info() I added to see if the script action started executing or not. but it is not executing even after the event is processed

Hi,

please share how are you triggering the event?

possibly the object of GlideRecord you are using is invalid

What you can do is

1) send the sys_id of the record in event parameter

2) in script action get that sys_id and query that table and then use that as GlideRecord object

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

BR Condition:
find_real_file.png

BR SCRIPT:
find_real_file.png

 

EVENT REGISTRY:
find_real_file.png

Schedule Trigger:
find_real_file.png

SCRIPT Action:
find_real_file.png

 

REST MESSAGE: The rest message is working fine when we are manually triggering it.

Hi,

please share the BR script and script action script here and not the screenshot

I think the problem is the current object not working

If you share the script I could help

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

BR Script:

(function executeRule(current, previous /*null when async*/ ) {

var when = new GlideDateTime();
var delay = new GlideTime();
delay.setValue("01:30:00");
when.add(delay);
gs.eventQueueScheduled("Resolution_notification_dely", current, "", "", when);

})(current, previous);

 

SCRIPT ACTION SCRIPT:

var r = new sn_ws.RESTMessageV2('[HP OO] Incident Update', 'get');
r.setStringParameter('uuid', current.correlation_id.toString());
r.setStringParameter('number', current.number.toString());
var response = r.executeAsync(); //Might throw exception on request failure
response.waitForResponse(60); //wait up to 60 seconds
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

if (httpStatus != 200) {
var s = new sn_ws.RESTMessageV2('[HP OO] Incident Alternate', 'get');

s.setStringParameter('uuid', current.correlation_id.toString());
s.setStringParameter('number', current.number.toString());
var response = s.executeAsync(); //Might throw exception on request failure
response.waitForResponse(60); //wait up to 60 seconds
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

}