The CreatorCon Call for Content is officially open! Get started here.

disable selction of past dates in sate feild

Its_Azar
Tera Guru
Tera Guru

when date field is opened i want to see only current and future dates and past dates should be greyed out, and should not be able to select these dates.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India
4 REPLIES 4

Viraj Hudlikar
Tera Sage
Tera Sage

Hello @Its_Azar 

You cannot grey out date. To restrict user from selecting past date you can create a UI Policy for the table and set condition as showcased below:

VirajHudlikar_1-1738223528717.png

 

VirajHudlikar_2-1738223644057.png

Output:

VirajHudlikar_3-1738223682590.png

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

@Its_Azar 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Thanks & Regards,
Viraj Hudlikar.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Its_Azar 

 

Agree with @Viraj Hudlikar  , use UI policy to restrict the user to select the future date only , it is best and no code.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@Its_Azar 

you cannot grey out but you will have to add validation for this using either client script OR ui policy

Viraj has shared the UI policy based approach

Please refer below script which you can write on change of that field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {
        return;
    }

    //current date
    var currentDateObj = new Date();
    var currentDateStr = formatDate(currentDateObj, g_user_date_format);
    var currentDateNum = getDateFromFormat(currentDateStr, g_user_date_format);
    var startDateNum = getDateFromFormat(newValue, g_user_date_format);
    if (startDateNum < currentDateNum) {
        alert("Date is in the past");
        g_form.clearValue("your_date_field");
        g_form.setMandatory('your_date_field')
    }
}

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