How to schedule an email notification for every two weeks

kkswamy
Tera Expert

Hi,

I have a requirement to send an email notification for every 2 weeks if the ticket is in "investigation" state for 2 weeks, and another email in 4 weeks and next one 6 weeks and so on...

Below is the scheduled job i created which will trigger daily at 8am,

var mpp = new GlideRecord('incident');
mpp.addQuery('sys_created_on','<=',gs.daysAgo(14));//created 14 days ago
mpp.addQuery('state','2');//ticket in investigation state
mpp.query();
while(mpp.next()){
//Create an event that will be used to trigger a notification
gs.eventQueue("incident.inactivity", mpp);
}

But,

problem with this script is, it will trigger every day for a single ticket and email will go everyday after 2 weeks but i need to send an email only once for every two weeks with above conditions.

Any help much appreciated.

Thanks.

1 ACCEPTED SOLUTION

kkswamy
Tera Expert

Below is the script for my requirement, it worked well after testing.

var todayDate=gs.nowDateTime();
var mpp = new GlideRecord('incident');
mpp.addQuery('state','2');//incident state is 'active'
mpp.query();
while(mpp.next()){
var dateDiffrence=gs.dateDiff(mpp.sys_updated_on.getDisplayValue(),todayDate.getDisplayValue(),true);
var i=parseInt(dateDiffrence/86400);//converting seconds to days and result in to integer format
gs.log('no.of days '+i);
if(i%14==0)//if remainder is 0 then only trigger the event
{
//Create an event that will be used to trigger a notification
gs.eventQueue("incident.inactivity", mpp);
}
}

View solution in original post

9 REPLIES 9

Christine A1
Mega Expert

mpp.addQuery('sys_created_on','<=',gs.daysAgo(14));//created 14 days ago

 

should be

 

mpp.addQuery('sys_created_on','=',gs.daysAgo(14));//created 14 days ago

then have the job run daily. you might need to make sure you are getting date only and not date and time

Thanks for the reply, but still this will not fulfill my requirement.

i have to send an email for every 14,2*14,3*14... until the state moved to next stage.

Deepak Ingale1
Mega Sage

You might have to create a temporary table where you can track those notifications being sent and on what day. You can call it as notifcation remider table

 

Note: Please mark reply as correct if it answers your question

Okay thank you, but we are not allowed to create custom tables in our instance for this kind of small enhancements.