how to populate Yes or No alert?

Rithvik2
Tera Contributor

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

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Elijah Aromola
Mega Sage

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
}

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks @Ankur Bawiskar 

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 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader