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

@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

sunil maddheshi
Tera Guru

@LokeshwarRV 'Hi , Please create UI policy and give condition like planned start date 'after' today. and select rever if false, and in UI policy action select clear value and in message write "Start date must be in the future for Normal changes.'"

 

Please mark correct/helpful if this helps you!

 

Hello Sunil,

 

     As per you told i have just created UI policy and action like below . please check it is there any mistake. if there please correct it otherwise let me know

Manohararuna_0-1747737501461.pngManohararuna_1-1747737570109.pngManohararuna_2-1747737619168.png

 

Regards,

 D Manohar Reddy

@Manohararuna 

give condition like below and dont create UI policy action if you are using script, also before message give g_form.clareValue('yourfieldname');

U1.png

Please mark correct/helpful if this helps you!