Exclude Custom Holiday Shedule when calculating End Date.

EricG
Kilo Sage

Hello All:

 

I have a need to exclude our corporate Holiday schedule from an HR process.

The Process = A specific group of 60+/- people are required to take 5 consecutive business days off each year.

HR needs to have their access to any/all corporate programs/resources terminated during that time.

 

I've successfully accounted for Weekends in my script (below):

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var cdt = g_form.getValue('start_date');
    var addtime = ''; 
    var addtype = 'day'; 
    var myGDT = new Date(cdt);
    if (myGDT.getDay() == 1) {
        addtime = 5;
    } else {
        addtime = 7
    }

    var ajax = new GlideAjax('ClientDateTimeUtils');
    ajax.addParam('sysparm_name', 'addDateTimeAmount');
    ajax.addParam('sysparm_fdt', cdt);
    ajax.addParam('sysparm_addtime', addtime);
    ajax.addParam('sysparm_addtype', addtype);
    ajax.getXML(doSomething);

}

function doSomething(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    //You could then take the new Date/Time answer and set the value of another field.
    var myDate = answer.slice(0, 10); //10/05/2022 24
    g_form.setValue('end_date', myDate);
    g_form.setValue('control_end_date', myDate);
    //alert(myDate);
}

 

Now, based on a users oversight, I need to take into account the Corporate Holiday schedule.  I have 4 different schedules, so I can't use the OOB Exclude Holiday/Weekends schedule.

 

I've seen other posts, but they don't seem to fit.   Any recommendations?

 

2 REPLIES 2

GlideFather
Tera Patron

Could not this be achieved code-less via SLA definition on a selected table, using the Schedule (e.g. 9-6 weekdays excluding holidays) and having the days off defined on that record?


KamilTerl_0-1728653849536.png

KamilTerl_1-1728653864661.png


PS: this might be challenging if it is not regularly repeated in the same date every year (similarly to Easter, a little different dates every year), but you can create the records for years ahead if known.

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


I have a "Schedule" entered for the Custom Dates.  Yes I understand it's tricky, since several of the holidays are not "Standard" like Easter, New Years, 4th of July....  I'm planning on having these entry updated by an API Call when new schedules are made available.

 

I've never used an SLA definition to control dates on a Catalog Item.

Could you explain?

 

THe catalog item documents Required Time off and creates several tickets for Manual Deactivation/Reactivation.

So any help you can provide will be appreciated.