In Oracle Apex, you can show alert messages using Dynamic Action of Alert type and JavaScript code. You can also create a dynamic action to execute JavaScript code for the alert message or just include apex.message.alert
in any JavaScript program. Here are the examples of both:
1. Show Alert Message Using Dynamic Action in Oracle Apex
In the below example, the alert message will be shown on a button click. To do this, we need to create a dynamic action for the button on click event. You can choose any event in Apex to show the alert message. Follow these steps:
Do right-click on the button and select Create Dynamic Action from the shortcut menu. Then for the True Action choose Alert and type your message in the Text box as shown in the below image:
Now when you will click on the button, you will get the message as shown below:
In the Text message box, you can reference a page item or the application item as shown in the below example:
Hello &APP_USER.
2. Show Alert Message Using JavaScript Code
You can use apex.message.alert
JavaScript API function to show alert messages in Oracle Apex. You can include this function in any JavaScript code or you can create a dynamic action to execute the JavaScript. The following is the syntax:
apex.message.alert( pMessage, pCallback);
pMessage
is the String to display the message in the dialog.pCallback
FunctionpCallback
is a function called when the dialog is closed.
Example - 1: Show the Hello World! message in alert using JavaScript.
apex.message.alert("Hello World!");
Example - 2: The following code will show the Hello message with the page item P10_EMPNAME
having the employee name.
apex.message.alert("Hello &P10_EMPNAME.");
Example - 3: In the following example, it will show the alert message and when the user will respond to the message by clicking on the OK button, it will call another JavaScript function named RunProcess()
.
apex.message.alert( "This will run a process, please be patient.", function(){ RunProcess(); });
Reference: JSDoc - Namespace: message
It doesn't work for me with any item on the page, just write Hello, I use apex.message.alert ('Hello &PX_MY_FIELD.');