Bharath kumar6
Tera Expert

Hi,

You can use onChange client script on the required field and write the code to check if the user is entering the past date.

 

Please mark correct/helpful based on impact.

Regards,

Bharath kumar

Shakeel Shaik
Giga Sage

Hi Gayathri,

Create onChange Client Script on Field u want to change.

 

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

    var currentDate = new Date(); //Current Date
    var selectedDate = new Date(g_form.getValue('u_date_field')); //Date field value

    if (currentDate.getTime() >= selectedDate.getTime()) {
        //Past Date on Date field should thrown an error near field
        g_form.showFieldMsg('You can not select a Past Date');
        return false;
    }

}
Thanks,
Shakeel Shaik 🙂

Hi Gayathri

 

If my above response is helpful, then Please mark as Correct Answer/Helpful.

 

If you have any queries, let us know.

 

Thanks 🙂

Thanks,
Shakeel Shaik 🙂

Hi,
g_form.showFieldMsg("u_date_field",'You can not select a Past Date'); 
we need to mention the field on which we need to show field message.

Raghu Ram Y
Kilo Sage

Hi, 

Try Below...It works.

Client Script : Onchange Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var udt = newValue;
    var ga = new GlideAjax("GetCurrentDateAndTime");
    ga.addParam('sysparm_name', 'GetDate');
    ga.addParam('sysparm_get_date', udt);
    ga.getXML(HelloWorldParse);

    function HelloWorldParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer == '5') {
            g_form.setValue('date_field_name', "");
            return false;
    }
}
}

Script Include

var GetCurrentDateAndTime = Class.create();
GetCurrentDateAndTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    GetDate: function() {
        var getNum = this.getParameter('sysparm_get_date');
        var nd = new GlideDateTime();
        if (getNum > nd) {
            return 5;
    },
    type: 'GetCurrentDateAndTime'
});