alert message is triggering twice and not clearing the value second time in the workspace

Community Alums
Not applicable

Hi Team,

I have a requirement where the sample size is a string field and It should take only positive numbers. I am using the onChange client script for the 'sample size' field. If I use negative numbers or alphabets or alphanumeric then the error message should come. the below script is working in native view but whereas in workspace alert message is getting twice and not clearing the value on same page second time also.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var regexp = /^[+]?\d*$/;

    if (!regexp.test(newValue)) {
        g_form.addErrorMessage('Please enter positive numeric value');
        g_form.setValue('u_sample_size', '');
    }
}
monishram_0-1728458293528.png

 

3 REPLIES 3

ersureshbe
Giga Sage
Giga Sage

Hello,

 

Could you please conduct a test? Instead of using g_form.addErrorMessage(), I would appreciate it if you could utilize 'alert' for testing purposes. The link provided below explains the same concept you are attempting to address.

 

https://www.servicenow.com/community/now-platform-forum/adding-script-to-validate-entry-only-include...

 

Regards,
Suresh.

Community Alums
Not applicable

Yes @ersureshbe @ I used alert also.. still it is coming twice and not clearing the value. 

Hi, Did flush the browser cache and test it or try the same for some other browser?

 

Regards,
Suresh.