Script Action triggered by an event from Business Rule not working

Milan13
Giga Expert

Hello,

I have a business rule, which triggers an event and sends notification after the event is triggered.

This works, however it should also change values of an incident form and this does not work, not sure why...

Business Rule (event triggered, notofcation tied to the BR sent..):

(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);
})(current, previous);

Script Action screen shot below (not working - not setting the values as required....)

Any idea why?

Thanks a lot.

Milan

find_real_file.png

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Milan,

1. Create after UPDATE Business rule and add below code:

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

if(current.u_off_hold_date != previous.u_off_hold_date){

gs.addInfoMessage("DATE:"+current.u_on_hold_reminder+" Updaated:"+current.sys_updated_on);
gs.eventQueueScheduled ("on.hold.reminder'" , current , gs.getUserID ( ) , gs.getUserName ( ) , current.u_on_hold_reminder) ;

})(current, previous);

2. Add log in script action: add log:

gs.log("Number:"+current.number);
current.state ='9';

current.assigned_to ='sysId of assigned to';
current.udpate();

3. Go to the Event log where you can find out the event when it is processed compare it the the updated date log. 

I think issue is with running timing of event or script action.

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

19 REPLIES 19

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You are executing this script action, triggered by an event. The script action uses current, though what is current? Haven't tested, though think this is your issue.

Perform a GlideRecord query in your script action.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you verified the event is actually executed? With a gs.info for example, don't know what u_on_hold_reminder is or that this is incorrect, or a getValue missing, etc..

Note, the Business Rule should be an after business rule. Else the eventQueueScheduled is not performed.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Yes, the event on.hold.reminder gets execured from Business rule as current.u_on_hold_reminder is a date/time field on the incident form at which the event gets fired as notification reacting to trigerrimg of this event gets sent without any problem.

The only issue is the script action, after the event gets fired and notification gets sent I need below script action field changes, but 

What I need is to set up field values on the incident form after the event on.hold.reminder gets fired and notification is sent as per below script action which is not working....

Business Rule:

(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);
})(current, previous);

 

Script Action:

current.state = 9;
current.assigned_to = "";
current.update();

Thanks a lot.

Milan

Rakesh B K
Kilo Contributor

Hi,

 

grab the oldvalue of the form field using getValue and then set the value of the newValue to be changed onSubmit...