How to prevent user from submitting the catalog item

redth
Giga Expert

When an user selects 'No' for a particular variable, an alert box should be displayed and also they should not be able to submit the form. I need to write a client script for this.

Can you assist me in achieving this?

Best,

Akshitha

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi,



You can use an onSubmit client script to do this validation.



Here is a small example (UNTESTED)!



function onSubmit() {


        if (g_form.getValue('your_variable') == 'No') {


                  alert('Invalid answer');


                  return false;


        }


}



Reference: Client Scripts - ServiceNow Wiki


View solution in original post

12 REPLIES 12

Chuck Tomasi
Tera Patron

Hi,



You can use an onSubmit client script to do this validation.



Here is a small example (UNTESTED)!



function onSubmit() {


        if (g_form.getValue('your_variable') == 'No') {


                  alert('Invalid answer');


                  return false;


        }


}



Reference: Client Scripts - ServiceNow Wiki


current is not defined in client scripts. You are trying to respond   too fast.


Right you are. Script corrected.



Up too early and typing too fast!


Thanks Chuck. It's working