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.

How to clear the Error Message popup previously?? (It keeps stacking up when hit the error and the first error unable to clear)

Jason Lau Chang
Giga Contributor

Hi Guys,

I have a OnSubmit Client Scripts as below, tried to add in "g_form.clearMessages();" in order to clear the precious error messages, but it still leaving the first error on top and unable to clear it. (If I remove the "g_form.clearMessages();" , the error will keep stacking up when the user press the Submit button for second / third time etc. 

 

Any suggestion on the ways to clear All the Error PopUp previously then only show the new Error Message (if any) ?? 

 

===================================================================

function onSubmit() {
if(g_form.getValue("Variable_1") == "Yes") {

g_form.clearMessages();
g_form.addErrorMessage("Not suitable for storing Government or Banking data.");

return false;
}

if(g_form.getValue("Variable_2") == "Yes") {

g_form.clearMessages();
g_form.addErrorMessage("Not suitable for storing Highly Confidential Data.");

return false;
}

if(g_form.getValue("Variable_3") == "Yes") {

g_form.clearMessages();
g_form.addErrorMessage("Not suitable for storing Personal Data (Beyond Business card details).");

return false;
}

}

=======================================================================

1 ACCEPTED SOLUTION

Jason Lau Chang
Giga Contributor

Hi Guys,

thanks for trying to help, I have solved this myself by using the OnChange function:

 

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

//When "will you be storing Government Data" selected with "No", it will clear the message
if (isLoading || newValue == 'No') {

g_form.clearMessages();
return;
}

}

View solution in original post

10 REPLIES 10

Jason Lau Chang
Giga Contributor

Hi Guys,

thanks for trying to help, I have solved this myself by using the OnChange function:

 

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

//When "will you be storing Government Data" selected with "No", it will clear the message
if (isLoading || newValue == 'No') {

g_form.clearMessages();
return;
}

}