Build following functionality on change request record

AaravOjha
Tera Contributor

Build following functionality on change request record

 

For normal change when start date is selected. Validate if the date is not from the past and force user to enter future date

 

For emergency change the start date can be past date.

 

Build this using client script on the planned start date field

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@AaravOjha 

you can have onChange on planned start date, enhance as per your requirement

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

    var changeType = g_form.getValue('type').toString();
    if (changeType == 'normal') {
        var date = new Date();
        var dateEntered = new Date(getDateFromFormat(newValue, g_user_date_time_format));
        if (dateEntered < date) {
            g_form.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');
            g_form.clearValue('start_date');
        }
    } else if (changeType == 'emergency') {
        // add your validation if any you want
    }
}

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

AaravOjha
Tera Contributor

Need to do using GlideAjax

 

@AaravOjha 

I already shared solution without GlideAjax and it should work fine

For using GlideAjax refer below

Date field should not take past date. 

It can be achieved using UI policy as well

No Code date validations thru (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