Monday, 2 March 2020

Start and End Data validation according to Data format ServiceNow



Start Date Validation :
On Change Client Script :

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


    if (isLoading || newValue == '') {

        return;

    }

    if (g_form.getValue('start_date') != '') {

        var dFormat = g_user_date_format;

        var tFormat = g_user_date_time_format;

        var today = getDateFromFormat(formatDate(new Date(), dFormat), dFormat);

        var sDate = getDateFromFormat(g_form.getValue('start_date'), dFormat);

        if (today > sDate) {

            alert(getMessage("Select date in the future"));

            g_form.setValue('start_date', '');

        }

    }

}



End Date Validation :
On Change Client Script :
 


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

    if (isLoading || newValue == '') {

        return;

    }

    if (g_form.getValue('start_date') != '') {

        var dFormat = g_user_date_format;

        var tFormat = g_user_date_time_format;

        var end = getDateFromFormat(g_form.getValue('end_date'), dFormat);

        var today = getDateFromFormat(formatDate(new Date(), dFormat), dFormat);

        var sDate = getDateFromFormat(g_form.getValue('start_date'), dFormat);

        if (today > end) {

            alert(getMessage("Desired End Date has to be a date in the future"));

           g_form.setValue('end_date', '');

        } else if (sDate != '' && end < sDate) {

            alert(getMessage("End date should not be before Start date"));

            g_form.setValue('end_date', '');

        }

    } else {

        g_form.setValue('end_date', '');

        alert(getMessage('First please select Start Date Of Limit Change'));

    }

}

No comments:

Post a comment