The CreatorCon Call for Content is officially open! Get started here.

How do i fire an event at a certain time / date?

benl
Giga Contributor

Hello!

I would like to send an email reminder 48 hours prior to the date specified in the activity_due field on the task table. How can I achieve this?

Eg. Fire an event at 08:00 22/11/2016 if the activity_due field is set to 08:00 24/11/2016.

Thank you in advance

Ben

9 REPLIES 9

benl
Giga Contributor

Thanks guys,



I appreciate your help with this, I am still new to Service-now so the more specific you could be the better!



I currently have the following set up, however the event is not being fired.



  • I have a date/time field on the 'wm_task' table called 'u_installation_due'
  • I have a business rule with the table set as 'wm_task', the condition set as 'u_installation_due' IS NOT empty, and script set as - gs.eventQueueScheduled("installation.reminder", current, gs.getUserID(), gs.getUserName(), current.u_installation_due);
  • I have an event in the event registry called 'installation.reminder'
  • I have an email notification set to run when event 'installation.reminder' is fired.


What do i need to write in the business rule script to make the event fire 2 days prior to the date in the 'u_installation_due' field?


Hi benl,


I would rather achieve it with Simple Scheduled job which runs daily and take care of sending the reminders(make sure you run this only once in 24 hours). in this approach you don't have to worry to cancel the future event if Installation data changes for any reason.


find_real_file.png



SCRIPT :


var gr = new GlideRecord('wm_task');


gr.addQuery('u_installation_due','>=',gs.daysAgoStart(2));


gr.addQuery('u_installation_due','<=',gs.daysAgoEnd(2));


while(gr.next()) {


  gs.eventQueue("installation.reminder", current, gs.getUserID(), gs.getUserName(), current.u_installation_due);


}




Hope that helps!!


Mark this thread answered in case you find this solution suitable.


Hi benl,



What ever you have trying to do is correct.



Go to business rules of the table wm_task. then create a new one called installation reminder..


1. when - After


2. Insert & Update checked


3. In the advanced add the script


Conditions:current.u_installation_due.changes()


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


// Add your code here
if ((current.u_installation_due <= gs.daysAgo(-2)))
{
gs.eventQueueScheduled("installation.reminder", current, gs.getUserID(), gs.getUserName(), current.u_installation_due);
      }
})(current, previous);


4. Save the business rule



Then create the Event entry, then Nofitication with the appropriate messages.



Result set.



When ever you add or update and you have some changes found in the field. Go to the event logs and see if you have a entry. If it before two days. It would create an entry and you see see the status as ready if it is going to run or it would say it is processed.



Please mark this helpful so that other can refer.



Regards


Param


Replace by this



var dateValue = new GlideDateTime(current.u_installation_due);;


dateValue.addDays(-2);


gs.eventQueueScheduled("installation.reminder", current, gs.getUserID(), gs.getUserName(), dateValue);


Chuck Tomasi
Tera Patron

You might find this useful. I built it specifically for reminder notifications. It can be done without any script (or pre-build the script based on your field inputs to help accelerate a solution.)



Scriptless Scheduled Jobs