Planned start date must be after current date

NikhithaNikki
Tera Contributor

I have created a field in Record producer which is planned start time. I have requirement that the planned start date must be after the current date.

6 REPLIES 6

sunil maddheshi
Tera Guru

@NikhithaNikki Hi create catalog UI policy and give condition somethinglike below and clear the value in UI policy action

U1.png

Please mark correct/helpful if this helps you

NikhithaNikki
Tera Contributor

I have created date/time field. it should be the validate the time also. Can you please help.

@NikhithaNikki 

the script I shared should handle this

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

    var selectedDate = new Date(g_form.getValue('start_date'));
    var todayDate = new Date(); // Now
    if (selectedDate.getTime() < todayDate.getTime()) {
        g_form.showFieldMsg('start_date', 'Planned start date must be after current date.', 'error');
        g_form.clearValue('start_date');
    }
}

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

Ankur Bawiskar
Tera Patron
Tera Patron

@NikhithaNikki 

you can use onChange catalog client script on start date variable

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

    var selectedDate = new Date(g_form.getValue('start_date'));
    var todayDate = new Date(); // Now
    if (selectedDate.getTime() < todayDate.getTime()) {
        g_form.showFieldMsg('start_date', 'Planned start date must be after current date.', 'error');
        g_form.clearValue('start_date');
    }
}

You can also achieve this Using Catalog UI policy with no scripting

No Code date validations through (Catalog) UI Policies 

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