How to set date/time field for weekdays only

Snow User5
Kilo Contributor

Hi All,

I have created one Date-Time field.

I want to throw an error message to user, when user selects date on either saturday/sunday.

User must select only working days(Mon-Fri)

How to achieve it ?

 

10 REPLIES 10

Hi @Raj Esh ,

Yepp it can be possible, For me below line of code worked.

if(dayCount == 5 || dayCount == 6) // 5 - sat & 6 - sun

 

Thank you for the information.

Cheers..!
Happy learning 🙂
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

Hello ,

If my response helped you please close the thread by marking appropriate response as correct so that it help others.

Cheers..!
Happy Learning:)
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar

Raghu Ram Y
Kilo Sage

Hi,

Use the simple below code, it works..tested..

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var date = new Date(newValue),
        day = date.getDay();
    if (day === 0 || day === 6) {
        g_form.addErrorMessage("It's a weekend");
        return false;
    }
}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

so what have you tried so far?

You can use UI policy for this

Something like this

find_real_file.png

find_real_file.png

Regards
Ankur

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

abhishekn05
Tera Contributor

It is calculating the daycount from the current day

For ex-if today is a tuesday it counts today as a daycount 1