confirm dialog with Yes/NO instead of Ok/Cancel and also redirect to URL upon NO reponse

ramprasad_purru
Tera Contributor

 @Ankur Bawiskar 

Hi Ankur, Kindly help me with this code. My requirement is to have Yes/No buttons. Upon No response, it has to open external URL. I have made changes in your code as below. Though it is working fine for me I just wanted to check with you whether it has any performance impact. Thought it is opening url in new tab but the dialog box remains in the page. how to disappear dialog box when I click on NO?

Below is my OnChange client script 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

 var dialog = new GlideModal('glide_modal_confirm'true300);
dialog.setTitle('Apps Assist Check Point');
dialog.setPreference('body''Did you check Apps Assist?');
dialog.setPreference('focusTrap'true);
dialog.setPreference('onPromptCancel', doCancel);
dialog.setPreference('onPromptComplete', doComplete);
dialog.render();
   
function doComplete() {
    callback(true);
        // use logic here when user clicks Yes
}
   
function doCancel() {
    callback(false);
   
       // use logic here when user clicks No
}
var abc;
function callback(abc)
{
    if(abc === false){
        top.window.open("https://mywebsite.com""_blank");
        g_form.setValue('state', oldValue);
       
    }

}
  
}
 
when I change state, this is dialog box appearing. Can we change the order of buttons? "Yes" first and "No" next.
 
ramprasad_purru_0-1753859335971.png

 

When I click NO the above dialog box should disappear like how it disappears if we click on Yes.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ramprasad_purru 

I believe since we are using the OOTB glide_modal_confirm, we can't change the position.

try this updated code and anyhow you need to close modal if it's Yes/No

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || newValue === '') {
    return;
  }

  var dialog = new GlideModal('glide_modal_confirm', true, 300);
  dialog.setTitle('Apps Assist Check Point');
  dialog.setPreference('body', 'Did you check Apps Assist?');
  dialog.setPreference('focusTrap', true);
  dialog.setPreference('onPromptCancel', doCancel);
  dialog.setPreference('onPromptComplete', doComplete);
  dialog.render();

  function doComplete() {
    // YES button clicked
    dialog.destroy();
    // Your logic for Yes goes here.
  }

  function doCancel() {
    // NO button clicked
    dialog.destroy();
    top.window.open("https://mywebsite.com/", "_blank");
    g_form.setValue('state', oldValue);
  }
}

it worked for me, Output below

modal yes no.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@ramprasad_purru 

I believe since we are using the OOTB glide_modal_confirm, we can't change the position.

try this updated code and anyhow you need to close modal if it's Yes/No

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || newValue === '') {
    return;
  }

  var dialog = new GlideModal('glide_modal_confirm', true, 300);
  dialog.setTitle('Apps Assist Check Point');
  dialog.setPreference('body', 'Did you check Apps Assist?');
  dialog.setPreference('focusTrap', true);
  dialog.setPreference('onPromptCancel', doCancel);
  dialog.setPreference('onPromptComplete', doComplete);
  dialog.render();

  function doComplete() {
    // YES button clicked
    dialog.destroy();
    // Your logic for Yes goes here.
  }

  function doCancel() {
    // NO button clicked
    dialog.destroy();
    top.window.open("https://mywebsite.com/", "_blank");
    g_form.setValue('state', oldValue);
  }
}

it worked for me, Output below

modal yes no.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

Hi Ankur,

 

Thank you so much for the quick response. 

Dialog box is still staying on the page for No response.

@ramprasad_purru 

it worked for me if you check the above gif.

On click of No you are setting field value, you don't want to save that?

Any browser console error you are getting when No is clicked?

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

@Ankur Bawiskar 

No . I don't want to save when I click No. 

No browser console errors but I  see warnings as below

 

ramprasad_purru_0-1753864000643.png