why confirm() is not working in ui action button

Jithender123
Tera Contributor

I am trying to create a button on incident table named password reset, for this I need a confirm box saying "are you sure you want to reset password" (yes/no). but unfortunately when I use confirm(), its not saving.

 

Please assist.

16 REPLIES 16

 

function reset_password() {
    var answer = confirm("Are you sure you want to reset the password?");
    if (answer) {
        gsftSubmit(null, g_form.getFormElement(), 'reset_password');
    }
}


if (typeof window == 'undefined'){
    <Write your server side script here>
}

 

Try something like this.

Have your server side script after the client side. Set redirect URL as well.

If my response helped please mark it correct .


Thanks and regards
Bharath

no I didn't worked unable to save it

Having the exact same issue, I think everyone else in the thread is misdiagnosing. Anytime you try to use confirm
eg. I change my line from
workflowconfirm = true

to

workflowconfirm = confirm("Confirm?")

 

when you go to press save the ui action is not saved, and you are shown this screen instead. Pressing the back arrow will return you to the ui action but without any of your changes saved.

MitchL_0-1750866947760.png

 

lukasz szumilas
Tera Guru

For ServiceNow i recommend using GlideModal instead of JavaScript Confirm.

Here is link how how GlideModal can be used with examples:

https://davidmac.pro/posts/2022-02-08-glidemodal/

For your case you would need to use in your UI Action (Client Type) this:

function resetPassword() {
  var gm = new GlideModal('password_reset_confirm');
  gm.setTitle('Password Reset Confirmation');
  // Optionally pass any needed parameters:
  // gm.setPreference('incident_sys_id', g_form.getUniqueValue());
  gm.render();
}

 
and then create UI Page.

SSJ
Tera Contributor

Hi @Jithender123

 

Please provide a screenshot of the UI action script component to better understand the issue.

 

Regards,

Somu