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.

Need to though an error message

Naresh43
Tera Contributor

Hi All,

I have created a field called "text" as a yes/no kind of variable so, when user selects the text as yes then we i have through an error meassge.

i have created like this onChange client script field as text 

its not working as expected can someone help me here ..

 

var output = g_form.getValue('text');
   if(output=='YES'){
    g_form.addErrorMessage('error message)');
   }
 
Regards,
Naresh
   
2 ACCEPTED SOLUTIONS

Maddysunil
Kilo Sage

@Naresh43 

Please validate the backend name of your choices inside dictionary of 'text' field. I am assuming Yes as true and no as false. Below is the script:

 

function onChangeText() {
    var output = g_form.getValue('text');
    if (output == 'true') {
        g_form.addErrorMessage('Error message: You selected "Yes" for the text field.');
    } else {
        g_form.clearMessages(); // Clear any existing error messages
    }
}

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

View solution in original post

@Naresh43 

Form does'nt get submitted for onchage client script, Try using on submit client script.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

View solution in original post

16 REPLIES 16

Naresh43
Tera Contributor

Hello All,

I have tried all the scripts but no luck.

can someone help me on this 

Please use on submit client script and try once