Untitled

 avatar
unknown
plain_text
13 days ago
1.1 kB
3
Indexable
(function run() {
    // Create a GlideRecord object for NeedIt tasks
    var gr = new GlideRecord('u_needit_task'); // Make sure to use the correct table name
    var today = new GlideDateTime();           // Get the current date/time
    
    // Query for overdue NeedIt tasks
    gr.addQuery('due_date', '<', today.getValue());
    gr.addQuery('active', '=', true);          // Only get active tasks
    gr.query();

    // Initialize an array to hold overdue task sys_ids
    var overdueTasks = [];

    // Iterate through results and collect the sys_ids of overdue tasks
    while (gr.next()) {
        overdueTasks.push(gr.sys_id.toString());
        // Optionally, you can log information or take actions on each task
        gs.info("Overdue NeedIt Task: " + gr.number + " with sys_id: " + gr.sys_id);
    }

    // Optionally send notifications or alert users regarding overdue tasks
    if (overdueTasks.length > 0) {
        // Example: Send email notification
        // gs.eventQueue('needit.overdue.tasks', null, overdueTasks.join(','), null);
    } else {
        gs.info("No overdue NeedIt tasks found.");
    }
})();
Leave a Comment