Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Past Date on Date field should thrown an error near field

Gayathri5
Tera Guru

Hi Experts,

 

My requriement is I have only 1 date field whenever i select past date from today it should show field error message. I tried using UI policy but only for 1st time it's working,if i keep on checking again and again the error is not occuring.

Please somebody help me what is the best approach for this?

Regards,

Gayathri

7 REPLIES 7

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'
});