Validation of Planned start date and planned end date

NikhithaNikki
Tera Contributor

I have created record producer with the variables planned start date and planned end date of variable type date/time. I have requirement that planned end date should be greater than planned start date. How to achieve this in ServiceNow.

4 REPLIES 4

Bhavya11
Kilo Patron

Hi @NikhithaNikki ,

 

Since these are date/time fields, the values pictured aren't equal.  I would try the low-code scripted UI Policy approach

Please refer this 

 

Thanks,

BK

Ankur Bawiskar
Tera Patron
Tera Patron

@NikhithaNikki 

you can use onChange catalog client script on planned end date with this logic

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }
    //Type appropriate comment here, and begin script below

    g_form.hideFieldMsg('end_date');

    if (g_form.getValue('start_date') != '' && g_form.getValue('end_date')) {
        var start = new Date(g_form.getValue('start_date')).getTime();
        var end = new Date(g_form.getValue('end_date')).getTime();
        if (end < start) {
            g_form.showFieldMsg('end_date', 'End date must be after start date.', 'error');
            g_form.clearValue('end_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

@NikhithaNikki 

Thank you for marking my response as helpful.

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

@NikhithaNikki 

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.

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