Dynamic Actions: Set Value [Oracle APEX 18.2]

Updated: Dec 3, 2018

There are several reasons to love Oracle Application Express (APEX) and in this post we will see one of these reasons: Dynamic Actions - Set Value

But... what are dynamic actions?

Dynamic actions in APEX allow developers to declaratively define client-side behavior even without knowing JavaScript. With dynamic actions you can set a value for an item, hide or display a region based on developer-defined conditions or events, all very simply.

Set Value

In this post - which will be the first to talk about dynamic actions - we will see the dynamic action "Set Value". To illustrate the use of this dynamic action, we will use a very simple mathematical operation: Factorial calculation.

Remembering that my goal is not to talk about mathematical operations but rather about dynamic actions in Oracle APEX. In this example we will have a region with 2 items and a button. Our dynamic action will be executed by pressing the "CALC_FACT" button.

Page Items:

P8_FACT_NUM -> Number Field

P8_TOTAL_FACT -> Display Only

1. In the Page Designer, right click on the button of our page and select "Create Dynamic Action".

A dynamic action with the following settings will be created:

2. We define a name for the dynamic action and click on it with the right mouse button and select "Create TRUE Action".

3. We define the "Set Value" action and, to perform the factorial calculation, we select the "PL/SQL Function Body" set type.

4. In PL/SQL Function Body we created the following block of code:


    l_x   number := :P8_FACT_NUM; -- Input Item
    l_y   number default 1;
    l_str varchar2(100) default l_x;
    while l_x > 0 loop
        l_y := l_y * l_x;
        l_x := l_x-1;
        if l_x> 0 then
            l_str := l_str || ' x '|| l_x;
        end if;
    end loop;
    l_str := l_str || ' = '|| l_y;
    return l_str;

5. Soon after, we select the page item to submit when executing our dynamic action and the item that will be affected by it. In this example, the input item that will be submitted in the dynamic action is P8_FACT_NUM, and the item that will receive the factorial value (Affected Element) is P8_TOTAL_FACT.

That done, we saved the changes on our page and our Dynamic Action is ready. All very simple and fast!

As an additional configuration, we can "ask" for the dynamic action to execute only when the input value of the P8_FACT_NUM item is less than or equal (<=) to 10, in the "Client-side Condition" session of our Dynamic Action.

In practice...

To see our Dynamic Action (Set Value) in action with a few more examples of its use, go to the demo application below.

Demo Application

Link: Learning APEX App

User (default): demo

Password: demo

#orclapex #oracle #dynamicactions #setvalue

Never Miss a Post. Subscribe Now!

Happy is the man that findeth wisdom, and the man that getteth understanding. (Proverbs 3:13)

Lucas Rayner © 2018 

  • Branco Twitter Ícone
  • Branca Ícone LinkedIn