Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Start date must be 10 working days ahead in catalog item

New user1212
Tera Contributor

Hi,

I need to set a limitation on the date that will work: start date must be 10 working days ahead.

Example. If I raise a new starter form on 11th December 2023, I cannot enter a start date of the 15th. Start date must be the 25th December at the earliest.
Any ideas?

3 REPLIES 3

Amit Gujarathi
Giga Sage
Giga Sage

HI @New user1212 ,
I trust you are doing great.
You can create a BR to add this validation as given below code

(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, 

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



and what if I want it to be set to only one variable in the catalog item?

 

I want the date in the catalog item to have this limitation: As the policy states an SLA of 10 working days, I think we should try and see if we can do it that way, so the start date must be 10 working days ahead.

 

Example. If I raise a new starter form on 11th December 2023, I cannot enter a start date of the 15th. Start date must be the 25th December at the earliest.

Ankur Bawiskar
Tera Patron
Tera Patron

@New user1212 

what do you mean by working days?

You can use schedule which considers holidays as well

what script did you start with?

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