This post will describe one method to show a Success Message from a Dynamic Action. A common scenario for an APEX page is to have a button that will submit the page, and have a page process perform some PL/SQL which includes a message defined in the "Process Success Message" that is displayed when the page is re-rendered.
To avoid the page submission and re-rendering we may want to perform the PL/SQL by using Dynamic Actions. Although we can perform the PL/SQL using an "Execute PL/SQL Code" dynamic action, the dynamic action definition does not include an option for defining a "Process Success Message".
In the example ( demo ) we have a page that contains a report and a button. Each time the button is pressed some PL/SQL code will be run to add a record to the table referenced in the report.
We could simply add an alert action to our dynamic action to give a browser message to the user but for this example we want to mimic the APEX success message. The success message displayed on the paged varies from theme to theme and is dependent on the page template we use for a page.
This example will use the "One Level Tabs - No Sidebar" template from the standard APEX Theme "26. Productivity Applications". Looking at the page template we see the #SUCCESS_MESSAGE# substitution string is located after the #REGION_POSITION_01# substitution string and a little bit before the "uOneCol" div element. Looking further down the template definition, in the Subtemplate group of items, is the "Success Message" template definition.
Copy the code from the Success Message field to be used later.
Create a Dynamic Action that will be executed when we click a button.
Create a "Execute PL/SQL Code" true action that will perform the desired PL/SQL.
Next create a "Refresh" true action that will reload the report dynamically on the page.
Add the following code to the true action:
var messageHtml = '';
messageHtml = '<section class="uRegion uWhiteRegion uMessageRegion clearfix" ';
messageHtml += ' id="uSuccessMessage">';
messageHtml += ' <div class="uRegionContent clearfix">';
messageHtml += ' onclick="$x_Remove(\'uSuccessMessage\')" ';
messageHtml += ' class="uCloseMessage"></a>';
messageHtml += ' <img src="/i/f_spacer.gif" class="uCheckmarkIcon" alt="" />';
messageHtml += ' <div class="uMessageText">';
messageHtml += ' New Message Record has been Added.';
messageHtml += ' </div>';
messageHtml += ' </div>';
messageHtml += '</section>';
- Replace the #IMAGE_PREFIX# substitution string with the image prefix on your installation.
- Add a backslash (\) in front of the single quotes to escape them.
- Replace the #SUCESS_MESSAGE# with the actual message you want to be displayed.
The last line uses some jQuery code to add the code in the messageHtml variable to the page before the "uOneCol" div.