Home > Net >  Oracle Apex Add IF Statement to set a value in a form
Oracle Apex Add IF Statement to set a value in a form

Time:05-31

I am working on a system in Oracle Apex 22.1 where there is a Form, where the user enters an amount of money to be validated by the company. There are 3 fields which are a select list P3_REQUEST_TYPE, a text field P3_AMOUNT and a select list P3_TYPE_CURRENCY. What I want to do is that if the user selects the option "Payment Request" in P3_REQUEST_TYPE, and according to the amount entered in P3_AMOUNT and the type of currency in P3_TYPE_CURRENCY (USD, JPY), put the value "1" in the field P3_FG_RT for validation reasons.

I would like to know if there is a way to do it through a IF function since through dynamic actions I have not been able to make it work, I would greatly appreciate your help.

The amounts for the "1" to be placed are: if it is greater than or equal to 5,000 and they are USD, or if it is greater than or equal to 18,000 and they are JPY.

CodePudding user response:

That looks like dynamic action, indeed.

  • its action would be "Set value"

  • type might be PL/SQL Function body:

    RETURN CASE WHEN    :P3_REQUEST_TYPE = 'Payment Request'
                    AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')
               THEN 1
           END;
    
  • items to submit: P3_REQUEST_TYPE, P3_TYPE_CURRENCY

  • affected elements: item, P3_FG_RT

Though, as you said that these are Select List items, I kind of doubt that return values really are "Payment Request" or "JPY" - I presume that you actually return their codes, not descriptions so CASE expression might need to be changed.

CodePudding user response:

The decision to use a dynamic action depends on the following question: is the value that needs to be set of importance before the page is submitted or does it only matter at submit time @Littefoot explained how to do the dynamic action but if this value is only needed after the page is submitted, it is easier to set the value of page item P3_FG_RT with a a computation (process point After Submit).

One way to implement this computation is:

  • Type: Static Value
  • Static Value: 1
  • Server Side Condition: Expression
  • PL/SQL Expression:
:P3_REQUEST_TYPE = 'Payment Request' AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')
  • Related