How to restrict user's by scheduling the plan start time and end time from out of the time range

nandini29
Tera Contributor

Hi,
need to implement a validation mechanism to restrict users from scheduling the Plan Start Time and Plan End Time outside the permitted maintenance window while creating a change request. for example,the allowed time range is between 10:00 PM CST and 4:00 AM CST. If a user attempts to schedule the plan start time before 10:00 PM CST, or the end time after 4:00 AM CST, the system should prevent the action and prompt the user with an appropriate message.

Could anyone suggest

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@nandini29 

you can use before update business rule for this

I shared script in this link, see if it helps

Help Needed: Restricting Planned Start Time in Change Module (CST Timezone) 

sharing here again, please enhance so that it picks 10PM on current date and adds 1 day and gets time for 4AM for next day

BR Condition: Planned Start Changes or Planned End Changes

(function executeRule(current, previous /*null when async*/) {
    var gdt = new GlideDateTime(current.planned_start_date);
    gdt.setTZ('America/Chicago'); // CST timezone

    var hour = gdt.getHourLocalTime();
    if (hour >= 9 && hour < 18) {
        gs.addErrorMessage('Planned Start Date cannot be between 9:00 AM and 6:00 PM CST.');
        current.setAbortAction(true);
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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