Date Variable on catalog items

KaralapatiN
Tera Contributor

I have a requirement to configure a date variable on a catalog item so that users can only select dates that are at least 10 business days out.

6 REPLIES 6

Dr Atul - LNG
Tera Patron

Hi @KaralapatiN 

 

Try like

 

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

    var minStartDate = calculateMinStartDate();

    if (current.start_date < minStartDate) {
        current.setAbortAction(true);
        gs.addErrorMessage("Start date must be at least 10 working days from today. The earliest possible date is " + minStartDate);
    }

    function calculateMinStartDate() {
        var today = new GlideDateTime();
        var workingDaysToAdd = 10;
        var totalDaysToAdd = 0;

        while (workingDaysToAdd > 0) {
            totalDaysToAdd++;
            var tempDate = new GlideDateTime(today);
            tempDate.addDays(totalDaysToAdd);
            var dayOfWeek = tempDate.getDayOfWeekUTC();
            if (dayOfWeek !== 0 && dayOfWeek !== 6) { // 0 = Sunday, 

@Dr Atul - LNG 

the requirement is for variable on catalog item but the code you shared is different and looks like a business rule which won't run for catalog item.

I shared it as a reference to use the logic, not to reuse the same BR.