Regarding onchange planned start date Validation in change Request

LokeshwarRV
Tera Contributor

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

    if (isLoading || !newValue) {

        return;

    }var changeType = gForm.getValue('type');

if (changeType.toLowerCase() === 'normal') {

        var ga = new GlideAjax('ValidateStartDateUtils');

        ga.addParam('sysparm_name', 'isFutureDateTime');

        ga.addParam('sysparm_selected_date', newValue);

        ga.getXMLAnswer(function(response) {

            if (response === 'false') {

                gForm.showFieldMsg('start_date', 'Start date must be in the future for Normal changes.', 'error');

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

            }

        });

    }

}this is client script

var ValidateStartDateUtils = Class.create();

ValidateStartDateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    

    isFutureDateTime: function() {

        var selectedDate = this.getParameter('sysparm_selected_date');

        if (!selectedDate) return false;

 

        var selected = new GlideDateTime(selectedDate);

        var now = new GlideDateTime();

 

        return selected.after(now) ? 'true' : 'false';

    }

});and script includes but it is not working 

 

13 REPLIES 13

I just edited my response above, can you have a look and let me know if you still see issues.

Ankur Bawiskar
Tera Patron
Tera Patron

@LokeshwarRV 

this should work for you without GlideAjax and Script Include

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

    var changeType = g_form.getValue('type');
    if (changeType.toLowerCase() == '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');
        }
    }
}

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

@LokeshwarRV 

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

@LokeshwarRV 

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

Hello Ankur,

 

        It's working fine but just clear the value of today date and today before date only. Developers should understand this but to understanding the non IT people i need to get one alert message for understanding purpose.

 

Regards,

D Manohar Reddy.