- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 08:48 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 08:51 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 01:26 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 01:26 PM
Can you please mark one of them as correct and close the thread.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 08:51 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 01:22 PM
Thanks Abhinay. It's working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 08:53 AM
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");
}
}