How to keep Yes or No, instead of Ok and Cancel in the Confirm alert

Lucky1
Tera Guru

Hello all,

 

On the Incident form, when the user is trying to save the form after the state has been moved to Resolved, then I need to display an alert with Yes or No, instead of Ok and Cancel using confirm("Validated with user?");

So, can someone let me know how can we do this?

 

 

Regards,

Lucky

1 ACCEPTED SOLUTION

@Lucky1 

business rule can't show you dialog box as dialog box only works from client side code

I suggested to use that dialog box code in the Close button

Did you try that approach?

Don't create any client script

function moveToClosed() {

    var dialog = new GlideModal('glide_modal_confirm', true, 300);
    dialog.setTitle('Confirmation');
    dialog.setPreference('body', 'Validated with user?');
    dialog.setPreference('focusTrap', true);
    dialog.setPreference('onPromptComplete', doComplete);
    dialog.setPreference('onPromptCancel', doCancel);
    dialog.render();

    function doComplete() {
        callback(true);
        g_form.setValue("state", "3");
        gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_closed");
    }

    function doCancel() {
        callback(false);
        return false;
    }
}

if (typeof window == 'undefined')
    setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}

AnkurBawiskar_0-1747129226310.png

 

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

19 REPLIES 19

SumanthDosapati
Mega Sage
Mega Sage

@Lucky1 

You can use GlideDialog for this.

Take this thread as reference for your script.

If you are unable to do it, feel free to reach out.

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Lucky1 

this should work for you in client script or any client side code

var dialog = new GlideModal('glide_modal_confirm', true, 300);
dialog.setTitle('Confirmation');
dialog.setPreference('body', 'Validated with user?');
dialog.setPreference('focusTrap', true);
dialog.setPreference('onPromptComplete', doComplete);
dialog.setPreference('onPromptCancel', doCancel);
dialog.render();
	
function doComplete() {
	callback(true);
        // use logic here when user clicks Yes
}
	
function doCancel() {
	callback(false);
        // use logic here when user clicks No
}

Output: how it looks

AnkurBawiskar_0-1747043159070.png

 

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, 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. thought 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', 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() {
    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);
       
    }

}
 
   
}

@ramprasad_purru 

Please post a new question for this as this is an answered post.

Share all the details in that script, screenshots.

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