- 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-18-2018 08:45 AM
@Chuck Tomasi, can you help me here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2018 08:52 AM
You can create scheduled job which will run periodically for every 14 days.
Select run field as periodically and Repeat Interval as 10 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2018 07:58 AM
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.
- 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
‎06-17-2020 05:43 AM
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