How to Show Alert Messages in Oracle Apex?

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:

Oracle Apex dynamic action for alert.
Oracle Apex dynamic action on button click event to show alert message dialog.

Now when you will click on the button, you will get the message as shown below:

Oracle Apex alert message example using dynamic action.
Oracle Apex alert message dialog output using the Dynamic Action of Alert type.

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 Function pCallback is a function called when the dialog is closed.
Oracle Apex Dynamic Action example to execute JavaScript code for Alert.
Oracle Apex dynamic action example to execute JavaScript code to show the alert message.

Example - 1: Show the Hello World! message in alert using JavaScript.

apex.message.alert("Hello World!");
Oracle Apex - apex.message.alert() example.
Alert message dialog output using the JavaScript Code.

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

Related Tutorials:

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

2 Comments

  1. apex.message.alert("Hello &P10_EMPNAME.");
    

    It doesn't work for me with any item on the page, just write Hello, I use apex.message.alert ('Hello &PX_MY_FIELD.');

Comments are closed.