Usage of the confirm/confirmDelete JavaScript. How to generate the question text dynamically

This article describes the way you can use the confirm/confirmDelete JavaScript routine (confirm for versions after Apex 4.0 and confirmDelete for versions until Apex 4.0), which is defined in the standard APEX JavaScript library, so it can be used in the applications that the users develop and use, the way that this routine calls the process execution and the way it's value can be set dynamically.

 You have probably noticed the fact that after you create a form on a table or a view or a form on a table with report, with the page create wizard, with the delete operation included, the Delete button's target is an URL with the following value:

javascript:apex.confirm (htmldb_delete_message,'DELETE');

or

javascript:confirmDelete (htmldb_delete_message,'DELETE');

depending on the Apex version you use.

 

From this point on we will consider the code for Apex versions after 4.0. The principle is valid for version before 4.0 as well but with confirmDelete instead of apex.confirm.

Therefore, when you push the Delete button, a window will pop up asking you to confirm that you really want to perform the delete operation.

Also you will notice the fact that in the page attributes section, the htmldb_delete_message used in the confirmDelete JavaScript routine is defined in the JavaScript field (Apex 4.0 or more) or in the HTML Header field (versions until Apex 4.0).

The value is set to a pre-defined the predefined "DELETE_CONFIRM_MSG" value which is by default the text: Would you like to perform this delete action?

Obviously you can use this JavaScript routine whenever you want to ask confirmation from the user that he really wants to run a certain task after pushing a button. And of course you can change the text that the popup window displays.

The routine definition is normally as follows:

javascript:apex.confirm (htmldb_delete_message,'DELETE');

where the first parameter represents the text that is displayed in the popup window and the second parameter is the request that is set. The second parameter is important when triggering the needed process. Let's consider that we have a button called Execute, with the confirmDelete routine added, that when confirmed launches the execution of a process called Data Execution. The Execute button's target field contains the following JavaScript routine:

javascript: apex.confirm ('Are you sure you want to submit the data you entered?','DATA_EXEC');

Then, the process must be set to trigger not when the button is pressed, but when the request has the DATA_EXEC value. The Conditional Processing field of the Data Execution process must look like this:

In certain cases you might want the question to be different based on a certain criteria. This means that the question text needs to be dynamic, changing its value to your need. In order to achieve this  you need to create a page item which will be used to store the value of the question. Let's call this item P1_QST_TXT (here we considered that we are in page 1, that's where the 1 comes from, instead should be the number of your page) . Then the confirmDelete JavaScript routine for the Execute button will receive the value of the newly created item, and will become:

javascript: apex.confirm (&P1_QST_TXT.,'DATA_EXEC');

The value of this P1_QST_TXT item has to be set in a Before/After Header/Regions/Footer process. This is a little tricky. Simply setting the value like this

:P1_QST_TXT :=' Are you sure you want to submit the data you entered?';

should work, you would think. Well it doesn't. The value of the P1_QST_TXT field must also contain the ' ' characters. Therefore the assignment has to be:

:P1_QST_TXT :=''' Are you sure you want to submit the data you entered?''';

or

:P1_QST_TXT :=''''||' Are you sure you want to submit the data you entered?'||'''';

And of course if you need the question to be dynamic, based on a certain criteria, then the value of the P1_QST_TXT item must be set to comply with your needs. Let's say that you need to have in the question text the name of the product that you submit the data for, and that this name is stored in a page item called P1_PRODUCT.

The assignment will become:

:P1_QST_TXT :=''' Are you sure you want to submit the data you entered for product '||:P1_PRODUCT||'?''';

And now pushing the Execute button for two different products, let's say printer and computer will look like this:

Leave a Reply