Send notification 30 days prior to end date

a2gupta
Giga Contributor

Hi all,

I have a table called 'u_contractors' where the collumns are Name,start date,end date and reminder date. Whenever someone submits a particular request,through a business rule,the Requested For,Start date,End Date gets auto updated in the table from the information provided in the request. Here is the business rule:-

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

  // Add your code here

var gr = new GlideRecord('u_contractors');

gr.initialize();

gr.u_start_date = current.variables.Start_Date;

gr.u_end_date = current.variables.End_Date;

gr.u_name = current.request.requested_for;

gr.insert();

})(current, previous);

Now the requirement is to send notification to the user's manager 30 days prior to the end date and ask whether he would like to extend the end date or not. I have created a scheduled job for this which runs daily. Here is the script for this:-

Schedule.PNG

But when I'm clicking Execute Now after submitting the request,nothing is happening,while it should fire the event if today's date is one month prior to end date and also update populate the reminder date collumn by today date.

Is there something I'm missing or is there an error in the code?

Any suggestions are welcome.

Thanks.

2 REPLIES 2

Alikutty A
Tera Sage

Hi Anurag,



Scheduled jobs run at server side, so alert won't work in it. You can either user gs.log or gs.info to see if it is entering inside loop.



Please try this code after modifying it



var gr = new GlideRecord('u_contractors');


gr.addEncodedQuer('u_reminder_date_atISEMPTY^u_reminder_dateRELATIVELE@dayofweek@ago@30');


gr.query();


while(gr.next()){


    gs.log('Event triggered');


  gs.eventQueue();


  //Remaining code


}



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


ravish2
Giga Expert

I would suggest using eventQueueScheduled. Its not a good practice to have a schedule job run on daily basis whenever it can be avoided. Use this eventQueueScheduled function to trigger notification at a specific time in future in your case it will be 30 days prior end date.