Search code examples
oracle-apexoracle-apex-5oracle-apex-5.1

Oracle APEX Compare Two Items Values to Fire a Dynamic Action


I want to create a Dynamic Action thats when my page item P2014_BALANCE < P2014_CURRENT_PRICE then P2014_CURRENT_PRICE gets the static value 0. The problem is that i can't compare these two page items. I try to when section in my Dynamic Action to use Javascript expression like this:

if(apex.item( "P2014_CURRENT_PRICE " ).getValue() < apex.item( "P2014_CURRENT_PRICE " ).getValue()){
alert('Wrong Number');
};

but when my page loads gets an error (even Fire on Initialization = False).

I also try this: enter image description here

still nothing.


Solution

  • This is a web application. All page items contain string values. So if you want to do number comparison, make them numbers:

    if (Number(apex.item( "P2014_BALANCE" ).getValue()) < Number(apex.item( "P2014_CURRENT_PRICE" ).getValue())) {
    alert('Wrong Number');
    };
    

    Note that in your example you have P2014_CURRENT_PRICE twice - that will always yield false anyways.

    This is how you would implement this in a dynamic action. Note that I tried on 21.1 but it should be similar in 5 (consider upgrading):

    Dynamic Action on Change of Item P2014_CURRENT_PRICE with client Side Condition of type Javascript Expression Source:

    apex.locale.toNumber(apex.item( "P2014_CURRENT_PRICE" ).getValue()) > apex.locale.toNumber(apex.item( "P2014_BALANCE" ).getValue())
    

    True Action with Action Set Value Set Type Static Assignment Value "0" Affected Element Item P2014_CURRENT_PRICE