Why i am getting same alert and error message twice in workspace?

KM SN
Tera Expert

I have configured on change client script to clear the dob value and to show alert or error message if the selecting date is in future. I tried with alert and error message both are reflecting twice.

 

when i tried with field error box its clearing the value first time and showing error box but on same page second time also if i have choose future value its not clearing the value why?

 

Can i have any inputs on it?

 

Client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
 
    var today = new Date();
//var currentDate = today.format('MM/DD/YYYY');
    var dob = g_form.getValue('date_of_birth');
 
alert(today);
alert(dob);
 
    if (dob < today ) {
 
        g_form.addInfoMessage('dob is less than today');
        return;
 
 
    } else {
 
 
g_form.addErrorMessage('DOB can not be future date!!');
g_form.clearValue('date_of_birth');
        //g_form.showErrorBox('date_of_birth', 'DOB can not be future date!!');
    }

reporter.PNG

9 REPLIES 9

Hemanth M1
Giga Sage
Giga Sage

Hi @KM SN ,

that's strange, could you  add "g_form.clearMessages()" before your alert messages and try

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

that worked, thanks.

Hi @INFJames ,

 

Accept the response if this helped you so that others can refer

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Actually it didn't completely work. It stops a duplicate error banner from appearing in SOW but then it doesn't execute the proceeding code on second trigger