Scheduled JOB Script for the Change Request

GBS
Tera Contributor

Hi, I'm using the script below, which is not working. Can anyone help me with the script to trigger the notification for the below
A notification has to be triggered 1 workday after the planned end date of a change is reached, and the Change Type is Normal, and the State is Implement

(function executeRule(current, gsr) {
    var gr = new GlideRecord('change_request');
    gr.addQuery('type', 'normal'); // Change Type = Normal
    gr.addQuery('state', 'implement'); // State = Implement

    // Planned end date is 1 working day ago
    var gdt = new GlideDateTime();
    gdt.subtractDays(1);
    // Skip weekends
    while (isWeekend(gdt)) {
        gdt.subtractDays(1);
    }

    gr.addQuery('end_date', '<=', gdt);
    gr.query();

    while (gr.next()) {
        gs.eventQueue('change.implement.overdue', gr, gr.sys_id, gs.getUserID());
    }

    function isWeekend(dateTime) {
        var day = parseInt(dateTime.getDayOfWeekLocalTime(), 10); // 1 = Monday, 7 = Sunday
        return day === 6 || day === 7;
    }
})(current, gsr);

 

10 REPLIES 10

@GBS 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader