Confirm property in actions

Objective

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.

Only in Web Panel Designer: Customizing when to show the confirm dialog

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>)"

Only in Web Panel Designer: Adding custom code when user clicks "No" in the confirm dialog.

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.