- 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 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 08:52 AM
current is not defined in client scripts. You are trying to respond too fast.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 08:55 AM
Right you are. Script corrected.
Up too early and typing too fast!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 01:23 PM
Thanks Chuck. It's working