How to use dynamic actions in Oracle APEX, with three examples

Oracle APEX dynamic actions step by step: show and hide an item, set a value with PL/SQL, and refresh a report when a filter changes, without submitting the page.

InstanceHubPublished 19 Nov 20267 min read

A plain APEX page does most of its work when the page is submitted: the user fills in a form, clicks a button, and the server processes it. Dynamic actions are how you make a page react before that happens. An item appears when another one is filled in, a value is worked out the moment a choice is made, a report refreshes when a filter changes, all without a full page submit.

They are also one of the first things an APEX interview moves on to after reports and forms. This guide explains what a dynamic action is made of, then builds three that cover most real uses.

The examples carry on from the courses table in How to build your first Oracle APEX app, with the columns title, product, level_name, start_date and seats. Any table of your own works the same way.

What a dynamic action is made of

Every dynamic action answers the same few questions:

  • When: the Event (for example Change, Click, Key Release or Page Load) and the element it watches, chosen by Selection Type: one or more items, a button, a region, a jQuery selector or a JavaScript expression.
  • Client-side Condition (optional): a test in the browser, such as "item is not null" or "item = value". It decides which set of actions runs.
  • True actions: what happens when the event fires and the condition is true, or every time if there is no condition.
  • False actions: what happens when the condition is false. They only make sense when there is a condition.

Each action has a type (Show, Hide, Set Value, Refresh, Execute Server-side Code, Execute JavaScript Code and more) and Affected Elements, the items or regions it acts on.

Where you create them

Open the page in Page Designer. There are two ways in:

  • In the Rendering tree on the left, right-click an item or button and choose Create Dynamic Action. The event and the element are filled in for you.
  • Or open the Dynamic Actions tab in the left pane (the lightning-bolt icon) and create one there.

The new dynamic action has one True action to begin with. Select the dynamic action or any of its actions to edit them in the Property Editor on the right.

Example 1: Show an item only when another has a value

On the course form, show Seats only once a Start date has been entered.

  1. Open the form page in Page Designer. The item names start with the page number, for example P3_START_DATE; use whatever your page shows.
  2. Right-click P3_START_DATE and choose Create Dynamic Action. Name it "Show seats when dated". The event defaults to Change.
  3. Under Client-side Condition, set Type to Item is not null and Item to P3_START_DATE.
  4. Select the True action. Set Action to Show, Selection Type to Item(s) and Item(s) to P3_SEATS.
  5. Turn on Fire on Initialization for this action, so the item is shown or hidden correctly when the page first opens, not only after a change.
  6. Under False, if APEX has not already added one, right-click and create an action Hide for P3_SEATS, also with Fire on Initialization on.
  7. Save and run. Clear the start date and Seats disappears; enter one and it comes back.

Hiding an item in the browser does not protect it. A user can still send any value for a hidden item, so anything that must be enforced belongs in a validation or in the database as well.

Example 2: Set a value with PL/SQL

Next, suggest a default number of seats as soon as a product is chosen.

  1. Right-click P3_PRODUCT and create a dynamic action named "Default seats". Event: Change.
  2. Select the True action and set Action to Set Value.
  3. Set Set Type to PL/SQL Function Body and enter:
return case :P3_PRODUCT
         when 'OIC' then 20
         else 30
       end;
  1. In Items to Submit, enter P3_PRODUCT.
  2. Under Affected Elements, choose Item(s) and P3_SEATS.
  3. Save, run, and change the product. Seats fills in without the page reloading.

Step 4 is the one people miss. A value the user has just picked exists only in the browser until it is sent to the server. Items to Submit sends it, so :P3_PRODUCT in the PL/SQL has the new value. Leave it out and the code sees whatever was in session state before, often nothing. The same rule applies to every action that runs code on the server.

Set Value has other types too: Static Assignment, JavaScript Expression and SQL Statement are the ones you will meet most.

Example 3: Refresh a report when a filter changes

The most common use of all: a select list above a report, and the report changes when the user picks a value.

  1. On the report page, add a page item P2_PRODUCT of type Select List with the products as its values, and a display value for "all" (a null value).
  2. Change the report region's SQL to use it:
select id, title, product, level_name, start_date, seats
  from courses
 where (:P2_PRODUCT is null or product = :P2_PRODUCT)
  1. On the region, under Source, set Page Items to Submit to P2_PRODUCT. This is the region's own version of Items to Submit: when the region refreshes, it sends the item's current value with the request.
  2. Right-click P2_PRODUCT and create a dynamic action, event Change.
  3. Set the True action to Refresh, with Selection Type Region and your report region.
  4. Save and run. Picking a product redraws only the report; the rest of the page stays as it is.

Forget step 3 and the report refreshes, but with the old filter value, which looks exactly like the dynamic action is doing nothing.

Running server code without a submit

The action Execute Server-side Code (called Execute PL/SQL Code in older versions) runs a PL/SQL block when the event fires, without submitting the page. It has two settings that matter:

  • Items to Submit: page items whose browser values the code needs.
  • Items to Return: page items the code changes, so the new values come back to the browser.

A typical pattern is a button whose dynamic action runs Execute Server-side Code to update a row, followed by a second True action, Refresh, on the report that shows it. True actions run in the order they are listed.

When it does not work

  • The code sees an old or empty value. Check Items to Submit on the action, or Page Items to Submit on the region.
  • Show and Hide are wrong when the page opens. Turn on Fire on Initialization.
  • Nothing seems to happen. Run the page, click Debug on the Developer Toolbar at the bottom, repeat the action, then open View Debug to see what was sent and what ran. The browser's developer console also shows JavaScript errors.

What to practise

  • Add a Confirm action before an Execute Server-side Code action, so the user has to agree first.
  • Disable a Save button until a required item has a value, with Enable and Disable actions.
  • Use Set Value with a SQL Statement to look up a value from another table.
  • Rebuild example 3 with an Interactive Grid instead of an interactive report, and compare.

Practise on an APEX instance

Dynamic actions only make sense once you have built a few and broken them. All of this needs an APEX workspace with a database of your own underneath, where you can create tables freely. Our APEX plan includes the latest APEX, admin access and its own ATP database.

See the Oracle APEX plans

Questions people ask

What is the difference between a dynamic action and a process in APEX?

A process runs on the server when the page is submitted or loaded. A dynamic action runs in the browser in response to an event, and can call the server without submitting the page. Saving a form is usually a process; reacting to what the user is doing is a dynamic action.

Why does my PL/SQL in a dynamic action see a null value?

The value the user just entered is still only in the browser. Add the item to **Items to Submit** on that action, or to **Page Items to Submit** on the region you are refreshing.

What does Fire on Initialization do?

It runs the action once when the page loads, as well as on the event. Turn it on for Show, Hide, Enable and Disable, so the page starts in the right state.

Can a dynamic action run JavaScript?

Yes. Use the **Execute JavaScript Code** action, or a JavaScript Expression as the client-side condition or as the Set Value type.