- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2018 11:31 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2018 07:47 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2018 11:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 08:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2018 11:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2018 11:46 AM
Okay thank you, but we are not allowed to create custom tables in our instance for this kind of small enhancements.