Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to trigger notification using gs.eventQueueScheduled based on a date/time field from incident form using business rule

Milan13
Giga Expert

Hello,

I have a custom date/time field placed in the incident form - once this is changed a business rule is triggered and notification should be sent at the time specified in given date/time field.

In my Business Rule I decided to use this method:

gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2' , gs.getValue('u_on_hold_reminder'));

u_on_hold_reminder - the date/time field mentioned

I made a notification which is sent once an event 'on.hold.reminder' is triggered as per the method above.

The problem is that it is triggered everytime the date/time field is changed and it does not reflect the date/time value for schedulling the event, not sure if I supply these parameters correctly.

Can anyone please advise?

Many thanks.

Milan

 

 

 

1 ACCEPTED SOLUTION

VIVEK ANAND
Mega Guru

gs.eventQueueScheduled does not return a value. so your if condition wont pass.

remove the If condition and place the code it should work fine.

Example:

gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);

current.state = 'Assigned';
current.assigned_to = "";
current.update();

Please refer to docs for more details on API: https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_SGSYS-eventQSched_S_O_S_S_O

 

Thanks,
Vivek Anand

Please Note: If my response helps you to fix this issue, please mark it as correct!

View solution in original post

11 REPLIES 11

Hello @VIVEK ANAND ,

I have received a requirement related to push notifications generation before the 24 hours and 2 hours of windows start field on work order task. For this we've created a business rule on insert and on update. In this we are successfully able to display the notification for 24 hour before as per the condition. But for 2 hours event it display both notification 24 hrs and 2 hrs. The 24 hrs notification displays before some time of 2 hrs. I will provide the BR script below

BR script:

 

var winStart1 = current.window_start ;

var gdt1 = new GlideDateTime(winStart1);

gdt1.addSeconds(-3600);

gs.eventQueueScheduled ("24.Hour.Push.Notification" , current , gs.getUserID(), gs.getUserName(), gdt1);

 

var winStart2 = current.window_start ;

var gdt2 = new GlideDateTime(winStart2);

gdt2.addSeconds(-3600);

gs.eventQueueScheduled ("24.Hour.Push.Notification" , current , gs.getUserID(), gs.getUserName(), gdt2);

 

 

Your help will be much appreciated as this requirement wants to be done on urgent basis.

 

Thanks and regards 

Aakanksha Lavande 

asifnoor
Kilo Patron

Hi Milan,

I suggest you write a scheduled job which runs every minute and in that look if the given time is equal to the value of onhold_reminder. If yes, then trigger an event, which internally triggers the notification.

Kindly mark the comment as a correct answer and helpful if it helps.