Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 06:43 AM
I am creating a scheduled job to to send out daily emails to the assigned user for incidents not active in 3 days excluding weekends. I have the condition for the exclusion below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 07:12 AM
are you saying you want to check if incident is assigned and still not updated for more than 3 business days?
what's your business requirement here? I am little confused
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 07:21 AM
Yes, I need to check for incidents assigned but have not been updated in 3 days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 07:36 AM
@MoeG82 To build your scheduled job for sending daily email notifications to assigned users of incidents that have not been updated in 3 business days (excluding weekends), you can follow the below sample script:
var scheduleId = '08a760a4a9fe198100ff1d8b29b9a71c'; // Replace with your actual schedule sys_id from cmn_scheduke other explicitly you will have to define date logic
var glideSchedule = new GlideSchedule(scheduleId);
// Get the current date and calculate the date 3 business days ago
var now = new GlideDateTime();
var threeBusinessDaysAgo = glideSchedule.subtract(now, 3, 'business');
// Query for inactive incidents not updated in the last 3 business days
var gr = new GlideRecord('incident');
gr.addActiveQuery(false); // Only inactive incidents
gr.addQuery('sys_updated_on', '<=', threeBusinessDaysAgo);
gr.addNotNullQuery('assigned_to'); // Ensure it has an assigned user
gr.query();
// Trigger the existing notification event for each matching incident
while (gr.next()) {
// Trigger the event for the existing notification gs.eventQueue('incident.reminder.inactive', gr, gr.assigned_to, gr.number);// if not then create a new notification and you can change param1 and 2 as per your requirement
gs.info("Notification event triggered for Incident: " + gr.number + " assigned to " + gr.assigned_to.getDisplayValue());
Please test on lower instance first.