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

Lucky1
Tera Guru

Hello ANkur and SUmanth,

 

I tried both of your logics but I am not getting any Dialog box with Yes or No.

Scenario I am using.

I have created an On Change Client script on State field of Change Request form,

So, when the state moves to CAB review, it has to show that dialog box,

Currently, I am getting alert message but the next lines of code not executing.

 

Please help.

 

This is my Code:

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

    //Type appropriate comment here, and begin script below
    if (newValue == '-3') {
        alert("New Value is " + newValue);
        // var dialog = new GlideModal('glide_modal_confirm', true, 300);
        var glideDialogClass = typeof GlideModal != 'undefined' ? GlideModal : GlideDialogWindow;
        var dialog = new glideDialogClass("glide_ask_standard");
        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
    }
}
 
 
 
Regards,
Lucky

 

@Lucky1 

I exactly copy pasted the same script which you gave (just by removing if loop for testing) and it worked for me.

See below screenshot

SUMANTHDOSAPAT_0-1747120661185.png

 

Can you try creating a new client script and check if it is working without any if condition first.

 

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

 

Ok Sumanth. 

But can you try this for Change request and on change of state to Implement.

Because if we manually change the state, then this dialog box will come, if the system is changing the state like on Change Request, this is not working.

 

 

Regards,

Lucky

@Lucky1 

What do you mean by system is changing? When you click on some UI action? Or server side change? or client side change based on another field?

Hi Sumanth,

 

Let me tell you clearly.

On the Change Request form, whenever the state is moving to Closed, then this dialog box has to be shown with Are you sure you want the CR to be closed? Yes / No,

If the user selects No, then the CR has to go back and update the state to Review.

Else, it should get closed, if the user clicks on Yes.

 

So, here I mean Whenever, we click on Close UI action button on the Change request form. the CR State will move to closed, So, before this closure, I want to show this dialog box with Yes or No options. Selecting No, will not take the CR to move forward and close.

 

 

Regards,

Lucky