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

vinothkumar
Tera Guru

Hi Aakash,



The reason why it is triggering daily is because, you are not updating the system fields in the scheduled job[gr.autoSysFields(false);] which makes the condition still valid, so it will trigger the email daily


Thanks Vinoth for the response.



Looks like it is a strange requirement. The mail should be sent after every 3 days but the updated by and updated fields should not be updated.


Hi Aakash,



If that is the case, you can update some work notes in the scheduled job itself like "change request due date reminder sent" and there by you can add some condition to your gliderecord in the scheduled job to check whether it contains work notes in the record, so we can skip it and this is just my opinion.


HI Vinoth,



Even if i update the worknotes the autoSysFields() function will not take the last updated date.