In this article, we’ll explore how to extend the standard functionalities of Oracle APEX by implementing Custom Events. This approach is particularly useful for performing advanced operations, such as customizing a delete action or styling specific cells in an Interactive Report. Custom Events allow you to go beyond the default behaviors, adding flexibility and control to your application.

1. What is a Custom Event in Oracle APEX?

A Custom Event is a user-defined event that can be triggered and handled within Oracle APEX. It allows developers to execute custom logic using JavaScript, PL/SQL, or both. This is ideal when built-in actions don’t meet your requirements.

Use Cases for Custom Events

  • Execute custom logic when a user clicks a button or icon within a row of an Interactive Report.

  • Trigger PL/SQL processes to interact with REST Data Sources from the client side.

  • Dynamically modify the content or style of a report based on specific conditions.

Interactive report displaying files uploaded for artificial intelligence training

We will start with the grid described in a previous article. From the development perspective, we will navigate to the column we created to manage the delete action.

Custom column customization in Oracle APEX displaying Custom Events configuration

Interactive column configuration showcasing how Custom Events are handled in Oracle APEX applications

In the Column Formatting section of the column, we can see an HTML code snippet like this:

Copy to Clipboard

Our custom event will be named deleteFile. This code dynamically inserts the file ID (#ID#) into the link’s attributes and triggers the custom event deleteFile with the file ID as the event payload. This ensures that when the delete icon is clicked, the corresponding file ID is passed to the event handler.

Building a Custom Event in Oracle APEX with event triggers and handlers

Step-by-step process of constructing a Custom Event in Oracle APEX, including event triggering and handling mechanisms

If we navigate to the Events section and create a Custom Event, the most important part is to ensure that the “Custom Event” field (highlighted in the image) contains the exact same name declared in the HTML code of the column mentioned earlier.

By matching the event names, we ensure that clicking the delete icon in the grid will trigger the Dynamic Action (DA_DELETE_FILE), allowing us to execute custom logic such as setting a variable, calling a PL/SQL process, or refreshing the report.

Within the Dynamic Action (DA_DELETE_FILE), we have three declared actions:

  1. “Set Value” – This captures the value passed through #ID# and stores it in a hidden field (P20010_FILE_ID).

Set value for custom event

Set value for custom event

  1. “Execute Server-side Code” – This runs a PL/SQL process that calls the REST Data Source to perform the delete operation, using P20010_FILE_ID as the parameter.

PL/SQL code for custom event

PL/SQL code for custom event

PL/SQL Code:

Copy to Clipboard
  1. “Refresh” – This updates the Interactive Report to reflect the changes after the deletion.

Refresh action for custom event

Refresh action for custom event

With all these steps, we have provided an introduction to Custom Events in Oracle APEX. We demonstrated how to use them to handle a custom delete action, integrating JavaScript, PL/SQL, and a REST Data Source.

In an upcoming article, we will expand our knowledge by using Custom Events to implement the file download functionality, building on the file upload process we covered in a previous article. Stay tuned!

For more information, please visit our company website or find us on APEX World for additional resources and updates!