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

@ramprasad_purru 

is the URL getting opened in new tab?

There is some issue going on in community that images are not visible.

please add it using browse feature and add as attachment to post

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 

Yes, URL is opening in new tab. Attached browser console image.

@ramprasad_purru 

I don't see any error related to modal.

What if you don't set the field using g_form?

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 

If dialog box disappears, then users will save the form with new state that I don't want them to do so.

@ramprasad_purru 

then save the form after setting and then reload

move the destroy line at the end

 function doCancel() {
    // NO button clicked

    top.window.open("https://mywebsite.com/", "_blank");
    g_form.setValue('state', oldValue);
   g_form.save();
    dialog.destroy();
  }

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