Send email after every 3 days

Aakash Shah4
Tera Guru

Hi Guys,

I need to send the Pending UAT remainder mail after every 3 days if the change request is not updated.

I have created a schedule job which is running daily.

This job is running only on weekdays as i have checked the conditional checkbox on the job.

The script for the schedule job is

var when = new GlideDateTime();

var delay = new GlideTime();

delay.setValue("72:00:00");

when.add(delay);   //passing this value in the eventQueueScheduled() function

var ps = 3;

var pn = parseInt(ps);

if(pn > 0){

var gr = new GlideRecord('change_request');

gr.addEncodedQuery('state=-5^priority=1');

gr.addQuery('sys_updated_on','<',gs.daysAgoStart(pn)); //not updated in 3 days

gr.query();

while(gr.next())

{

gs.eventQueueScheduled('change_request.inactivity',gr,gs.getUserID(),gs.getUserName(),when);

gr.autoSysFields(false);

gr.setWorkflow(false);

gr.update();

}

}

There is an email which is triggered from the event name.

I need this email should be sent after every 3 days, but this is sending email everyday.

Any thoughts on this?

1 ACCEPTED SOLUTION

Hi All,



I achieved this requirement by creating a field Count on the change request form.


The idea was to update the counter by 1 every time the job is running, in my case it is running daily so it will update the counter by 1 every day.


SInce I want to send email after every 3 days which meant on every 4th day, i applied a modulus operator to check the counter is divisible by 4.


In doing this i achieved my requirement of sending email after every 3 days without updating the Updated By and Updated fields.



Here is the schedule job which i wrote :



Since the job is to be run only on weekdays, i have checked the conditonal box and scheduled it for weekdays



Condition:



//Return 'true' to run the job


var answer = false;




//Get the day of week. 1=Monday, 7=Sunday


var now = new GlideDateTime();




//Run only on weekdays


if(now.getDayOfWeek() < 6){


  answer = true;


}


answer;





Run this Script:



var gr = new GlideRecord('change_request');


gr.addEncodedQuery('state=-5^priority=1');


gr.addQuery('sys_updated_on','<',gs.daysAgoStart(3));


gr.query();




while(gr.next())


  {



  var ct = gr.getValue('u_count');   // counter field created with default value 0



  if(ct % 4 ==0)   // since the email is to be sent after every 3 days


  {


  gs.eventQueueScheduled('change_request.inactivity',gr,gs.getUserID(),gs.getUserName());


  gr.autoSysFields(false);


  gr.setWorkflow(false);


  gr.update();



  }



  ct++;   // counter will be updated each time the job is run which is daily


  gr.setValue('u_count',ct); // capture the value of the updated counter


  gr.autoSysFields(false);


  gr.setWorkflow(false);


  gr.update();


}



I hope someone finds this helpful.


View solution in original post

12 REPLIES 12

Kalaiarasan Pus
Giga Sage

Change this and try


var when = new GlideDateTime();


when.addDays(3);


Hi Kalai,



I will give this a try. I wanted to know one thing, when the event is scheduled to be sent using the gs.eventQueueScheduled() function, it will be sent at a particular date and time as mentioned in the 5 parameter. Till that time this event would be stored i guess in the sys_trigger table. Maybe i was thinking we can pick the event from this table and glideRecord through this table to check if this event is already triggered then do not trigger again. Can you please let me know if my understanding about this is correct ?


It will store in sysevent table with Process On field containing the date/time on which the event will be processed.


I checked this table but it is not   showing any future events on the Process On field


This works just fine. Have you registered the event in the event registry ?



var when = new GlideDateTime();


when.addDays(3);


var gr = new GlideRecord('sysapproval_approver');


gr.addEncodedQuery('state=requested^sysapproval=b95dfde2db833200d8ccd421cf961931');


gr.query();


if(gr.next()) {


gs.eventQueueScheduled('final.approval.reminders',gr,gs.getUserID(),gs.getUserName(),when);


}