Scheduled job not triggering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hi,
I'm facing an issue with scheduled job, it is not triggering .
(function() {
var gr = new GlideRecord('sn_grc_task');
gr.addQuery('active', true);
gr.addQuery('state', 'NOT IN', '3,4,7,9');
gr.addQuery('end_date', '!=', '');
gr.query();
var now = new GlideDateTime();
var currentDate = now.getDate().toString(); // e.g., '2025-08-18'
var sevenDaysBefore = new GlideDate();
sevenDaysBefore.addDays(-7);
var sevenDaysBeforeDate = sevenDaysBefore.toString(); // e.g., '2025-08-11'
var sevenDaysAfter = new GlideDate();
sevenDaysAfter.addDays(7);
var sevenDaysAfterDate = sevenDaysAfter.toString(); // e.g., '2025-08-25'
while (gr.next()) {
var endDateStr = gr.getValue('end_date'); // e.g., '2025-08-18 00:00:00'
var dueDateOnly = endDateStr.split(' ')[0]; // extract '2025-08-18'
if (dueDateOnly == sevenDaysBeforeDate || dueDateOnly == currentDate || dueDateOnly == sevenDaysAfterDate) {
var assignedTo = gr.getValue('assigned_to'); // sys_id of assigned user
gs.eventQueue('sn_grc.due.date.overdue', gr, assignedTo, dueDateOnly);
}
}
})();
running daily
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Did you add gs.info() and see if query is satisfied or not?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
@Ankur Bawiskar
I tried executing the script using a scheduled job, but the email wasn't triggered.
However, when I ran the same script from a background script, the email was sent successfully.
Do you know why it works in a background script but not through the scheduled job?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
are you having any condition in scheduled job condition field?
If yes then that won't run when you click "Execute Now"
If the same script works from background script then it should run fine from job
make the job run periodically every 30mins for testing and then see if email triggers or not
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar no conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar
I tried setting it to run every 10 minutes, but it’s not executing as expected.