How to restrict users from submitting the CR on particular days

AnilM99
Tera Expert

Hi Team,

I have a requirement.

In our company, we have a blackout period for every quarter that lasts 15 days. 

 

eg., March 16th to March 31st

      June 16th to 30th

      September 16th to 30th

      December 16th to 31st

Requirement:

1. Restrict users from submitting the standard change request during the blackout period. 

2. Submit only emergency change requests.

 

Kindly help me on the same.

 

Thanks,

Anil

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@AnilM99 

did you configure the blackout schedule?

Create blackout and maintenance schedules in Change Management 

OR

you can use custom before insert business rule and stop the record insertion, something like this but please enhance

(function executeRule(current, previous /*null when async*/) {

    // Only apply to Standard Change Requests
    if (current.type != 'standard') {
        return;
    }

    var now = new GlideDateTime();
    var year = now.getYearUTC();

    // Define blackout periods for the current year
    var blackoutPeriods = [
        {start: year + '-03-16', end: year + '-03-31'},
        {start: year + '-06-16', end: year + '-06-30'},
        {start: year + '-09-16', end: year + '-09-30'},
        {start: year + '-12-16', end: year + '-12-31'}
    ];

    var today = now.getDate().getByFormat('yyyy-MM-dd');

    for (var i = 0; i < blackoutPeriods.length; i++) {
        if (today >= blackoutPeriods[i].start && today <= blackoutPeriods[i].end) {
            gs.addErrorMessage('Standard change requests cannot be submitted during the blackout period (' +
                blackoutPeriods[i].start + ' to ' + blackoutPeriods[i].end + ').');
            current.setAbortAction(true);
            break;
        }
    }

})(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

View solution in original post

2 REPLIES 2

Bert_c1
Kilo Patron

Hi @AnilM99,

 

Review the "blackout and maintenance schedules in Change Management". See:

 

change-management/task/t_CreateBlkoutMaintSched.html

 

Good luck

 

Ankur Bawiskar
Tera Patron
Tera Patron

@AnilM99 

did you configure the blackout schedule?

Create blackout and maintenance schedules in Change Management 

OR

you can use custom before insert business rule and stop the record insertion, something like this but please enhance

(function executeRule(current, previous /*null when async*/) {

    // Only apply to Standard Change Requests
    if (current.type != 'standard') {
        return;
    }

    var now = new GlideDateTime();
    var year = now.getYearUTC();

    // Define blackout periods for the current year
    var blackoutPeriods = [
        {start: year + '-03-16', end: year + '-03-31'},
        {start: year + '-06-16', end: year + '-06-30'},
        {start: year + '-09-16', end: year + '-09-30'},
        {start: year + '-12-16', end: year + '-12-31'}
    ];

    var today = now.getDate().getByFormat('yyyy-MM-dd');

    for (var i = 0; i < blackoutPeriods.length; i++) {
        if (today >= blackoutPeriods[i].start && today <= blackoutPeriods[i].end) {
            gs.addErrorMessage('Standard change requests cannot be submitted during the blackout period (' +
                blackoutPeriods[i].start + ' to ' + blackoutPeriods[i].end + ').');
            current.setAbortAction(true);
            break;
        }
    }

})(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