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

Glad to hear you got it working (with both our help.)



Would you be so kind as to please mark it as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list? Thank you


Can you please mark one of them as correct and close the thread.


Abhinay Erra
Giga Sage

Create a onSubmit client script and put this in the script


if(g_form.getValue("variable name goes her")=='Choice value of No"){


alert("something");


return false;


}


Thanks Abhinay. It's working


ryadavalli
Tera Expert

You can write a onChange script on that variable, and check if the variable == no, alert a message.



variable = your variable



function onChange(control, oldValue, newValue, isLoading) {


  if(newValue != oldValue && newValue == 'no')


{


alert("Your message");


}


}