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

Hi Karan,

 

I cannot give you the exact code but it is similar to the below post's solution by Imran Ahmad. The only difference is that I have not checked the client checkbox and therefore I don't have that Onclick field to call the function.

Abhi369
Tera Contributor

Right, so you need to actually convert it to a client-side UI Action by checking the box, adding the function name in the Onclick field and the "gsftSubmit" will re-run the code in the UI Action, this time on the server.

ttttttttting
Tera Contributor

I have the same problem. Have you solved your problem