Show confirmation dialog on record save/update

Tim D Scott
Giga Guru

Hi,

Apologies if this is a simple question, but I'm fairly new to ServiceNow UI development.

I have a table in my scoped application, that looks like this:

find_real_file.png

When the user selects save or clicks one of the update buttons I need to display a message, along with an OK / Cancel button.

If they click OK, the record is saved/updated as normal, if they Cancel the record is not saved/updated.

What's the easiest way to achieve this?

Thanks,

Tim.

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Tim,

You can create an onSubmit Client script with the following code:

function onSubmit() {
    var answer = confirm("Do you want to save the record? Press OK to save, Cancel to abort!");
	if (!answer) 
          return false;	
}

 

Please mark my answer as correct and helpful if it is relevant for you!

Thanks,

Filipe Cruz

View solution in original post

4 REPLIES 4

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Tim,

You can create an onSubmit Client script with the following code:

function onSubmit() {
    var answer = confirm("Do you want to save the record? Press OK to save, Cancel to abort!");
	if (!answer) 
          return false;	
}

 

Please mark my answer as correct and helpful if it is relevant for you!

Thanks,

Filipe Cruz

Thanks Filipe!

 

I would like to display different text for some of the buttons. Am I able to find out which operation/button has been clicked within the onSubmit() function?

 

Hello Tim,

The "Ok" and "Cancel" cannot be changed when using the "confirm" statement.

If you want to have something different there, you need to build up a UI page with custom buttons, each with a different label.

Please mark my answer as correct and helpful if it is relevant for you!

Thanks,

Filipe Cruz

Hi Filipe,

Sorry, I didn't word that very well! 

I have several buttons on the form, all of which fire the onSubmit() event, can I tell which one has been clicked and display a different confirm message for some of them?

Thanks (again!)

Tim.