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

kkswamy
Tera Expert

@Chuck Tomasi, can you help me here.

SaiRaviKiran Ak
Giga Guru

You can create scheduled job which will run periodically for every 14 days.

 

Select run field as periodically and Repeat Interval as 10 days

Thanks, but i have to check all the records every day, which one is created 2 weeks back and still in same state.

Any other way to send an email for every 2 weeks on a particular record, if the above conditions matched by running the scheduled job every day.

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);
}
}

Kailash Bhange
Kilo Sage
Kilo Sage

Hi There,
I have Created Article to send Notification using Schedule Job, please take a moment to review and update feedback.

Notify using Scheduled JOBS in ServiceNow


https://community.servicenow.com/community?id=community_article&sys_id=1dd55f001b255010ada243f6fe4bcba8

If the article helps you, please mark it as Helpful, Bookmark it, subscribe it and your feedback would be much appreciated.


Thank You!
Regards,
Kailash