Alert for confirmation after clicking a button

Abhi369
Tera Contributor

I have a button called "Cancel Request" on the top right corner of my form.

 

I want to create a alert/confirmation box with Yes and No button to prevent direct cancellation of the form.

I want a simple solution with a alert box only and not the UI Page solution. We already have a UI Action for this button but writing alert() or confirm() method of JavaScript is not working as that is Service side script.

 

Please help!

 

Thank you

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Yes you can do it as below:-

 

function cancelIncidents() {
    var answer = confirm("Are you sure you want to cancel it?");
    if (answer == true) {
        gsftSubmit(null, g_form.getFormElement(), 'cancelincidents');
} else {
    return false;
}
}

 

For more information check the below post:-

 

https://www.servicenow.com/community/developer-forum/add-confirm-pop-up-message-in-ui-action/m-p/197...

 

Please mark my answer as correct based on Impact.

 

View solution in original post

8 REPLIES 8

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Yes you can do it as below:-

 

function cancelIncidents() {
    var answer = confirm("Are you sure you want to cancel it?");
    if (answer == true) {
        gsftSubmit(null, g_form.getFormElement(), 'cancelincidents');
} else {
    return false;
}
}

 

For more information check the below post:-

 

https://www.servicenow.com/community/developer-forum/add-confirm-pop-up-message-in-ui-action/m-p/197...

 

Please mark my answer as correct based on Impact.

 

Abhi369
Tera Contributor

Hi Saurav,

 

Your code is correct, but it works when client checkbox is checked in the form. But what if it is server side script and we don't have any onclick field to call a function.

Abhi369
Tera Contributor

Hi Saurav,

 

Your solution is 50% correct.

Please see the below post from the community to get the solution.

 

Solved: While clicking the button a confirmation alert box... - ServiceNow Community

 

Thank you,

Abhishek

Karan Chhabra6
Mega Sage

Hi @Abhi369 ,

 

Please share the UI action script so that we can identify what exactly is the issue