- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 06:57 AM
I had a select box with options as yes or no or none[none is not a default one...its also a option]options..
when the user selected as "yes" then we need an alert popup with "Would you like to continue?" or "Not" options
If user selected No then we need to change the select box option to None else selected option i.e., Yes will be as it is..there will be no change
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 07:12 AM
Hi,
You can have onChange Client Script on that Select box variable
But you cannot have custom text on the confirm box. It would be OK and CANCEL
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// use valid choice value here
if(newValue == 'yes'){
if(!confirm('Would you like to continue?')){
// user clicked on CANCEL
g_form.clearValue('variableName'); // give your variable name here
}
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 07:01 AM
You could use a script like this:
var confirm = alert("Would you like to continue?" )
if(confirm == true) {
//user clicked ok
} else {
//user clicked cancel
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 07:12 AM
Hi,
You can have onChange Client Script on that Select box variable
But you cannot have custom text on the confirm box. It would be OK and CANCEL
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// use valid choice value here
if(newValue == 'yes'){
if(!confirm('Would you like to continue?')){
// user clicked on CANCEL
g_form.clearValue('variableName'); // give your variable name here
}
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 08:02 AM
Thanks
Perfect! It worked, but just a query....
Yes, No, None are three different options in my scenario....
when I used g_form.setValue() instead of clear I got an error but when I used clearvalue it directly updates to None...how does it directly updated to none as we have one more option NO also...
Note: None is a option which I have created
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 08:05 AM
Hi,
usually g_form.clearValue() will clear and won't trigger the onChange
if you use setValue() it would trigger the onchange again and that might cause loop as you are trying to set value on same variable on which onChange is written
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader