Confirm property in actions

There are cases in which it is required that the user confirms the action he has just performed to avoid accidental execution of actions which have important consequences in the system. K2BWebPanelDesigner includes an option in actions, through which the developer can achieve this in a very simple way.

How it works

Action nodes include a property called "Confirm", which establishes whether the action should require confirmation before executing or not. When confirmation is enabled for a certain action, clicking that action will cause the screen to show a dialog like this one:

ConditionalConfirm
Conditional confirm dialog in runtime

The message shown, in this case "Are you sure?", can be modified via the property "Confirm Message Expression". If the expression is a literal, must be between code.

If the user clicks on the "Yes" button, the action's code will be executed. If the user clicks on the "No" button, no actions will be performed.

Customizing when to show the confirm dialog

This feature is available in Web Panel Designer only.

Up to this point, the scenario covered in this guide is actions that require confirmation from the user every time they're executed. Another valid scenario, which is also available using K2BWebPanelDesigner, is a situation in which a confirmation is required only in some cases depending on the data being processed.

To provide flexibility in the definition of the condition, the user subroutine "U_ConfirmationRequired(<ActionId>)" is generated when the action requires confirmation. A boolean variable named "&ConfirmationRequired" is included as well. The default implementation of the subroutine simply sets this variable's value to true, thus providing the behaviour detailed above.

The developer can implement complex conditions inside this subroutine, the only requirement is that the variable &ConfirmationRequired holds the value "true" on the moment the subroutine ends, and confirmation must be required, and the value "false" if the opposite effect is wanted.

The following is an example of an implementation in which confirmation is required only if the value of "InvoiceTotal" is greater tan 1000. Note the usage of the "&ConfirmationRequired" variable.

ConfirmSubroutine
Example Implementation for "U_ConfirmationRequired(<ActionId>)"

Validation support

In many scenarios, it is necessary to validate an action before it is executed. If the validation fails, the confirmation dialog should be canceled. To achieve this, developers can add code to the U_ConfirmationRequired(<ActionId>) subroutine and set the variable &CancelActionExecution to false to cancel the action.

ConfirmSubroutineCancel
Example cancelation of dialog in "U_ConfirmationRequired(<ActionId>)"

Setting the default button

The developer can also include code in this method to choose which of the buttons in the confirm dialog (OK/Cancel) should have the focus when the dialog is opened using the "FocusOK" and "FocusCancel" methods.

Adding custom code when user clicks "No" in the confirm dialog.

This feature is available in Web Panel Designer only.

It is also possible to add custom code when the user clicks "No" by setting to true the "Generate Confirm No Subroutine" property. This will generate a U_ConfirmNo(Action) subrutine, in which developer can add custom code.