4 Replies Latest reply: Apr 18, 2012 9:53 AM by Amelie RSS

    Use of application Item with conditional validation

    Amelie
      Apex 3.2

      On a form, I have two lists :
      - Items TYPE contains A B C and D.
      - Item MANAGEMENT contains NULL, 1, 2 and 3.

      I want to validate that MANAGEMENT is not null only when the value in TYPE are A, B or C.

      I am using the condition "Value of Item in Expression 1 Is Contained within Colon Delimited List in Expression 2"

      I dont want to hard code these values (A B C) so I put them in an Application Item (I also need them somewhere else).

      If I use my application Item in the condition, the validation is not performed (I dont see it listed in debug mode.). If I use the real values (A B C), its working.

      Here's what I put in the Exp2 when using the application item :
      F126_CONST_BUSINESS_CASE:F126_CONST_PROJ_NON_PLANIFIE:F126_CONST_PROJ_PLANIFIE

      I also tried with the form v('F126_CONST_BUSINESS_CASE'): ...

      Any Idea ?
      Thanks in advance.
        • 1. Re: Use of application Item with conditional validation
          Arie Geller
          Hello Amelie,

          >> I am using the condition "Value of Item in Expression 1 Is Contained within Colon Delimited List in Expression 2"

          That means that the APEX engine treats Expression 2 as a string. In your case, literally the string of letters F126_CONST_BUSINESS_CASE:F126_CONST_PROJ_NON_PLANIFIE:F126_CONST_PROJ_PLANIFIE and NOT the values it represents.

          You should replace this string with the Substitution String notation of your application items:
          &F126_CONST_BUSINESS_CASE.:&F126_CONST_PROJ_NON_PLANIFIE.:&F126_CONST_PROJ_PLANIFIE.
          In this case, the APEX engine will substitute this string with a colon delimited string that includes the values of the application items, and now the validation should work as expected.

          Regards,
          Arie.

          -------------------------------------------------------
          ♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

          ♦ Author of Oracle Application Express 3.2 – The Essentials and More
          • 2. Re: Use of application Item with conditional validation
            Amelie
            Thank you, it worked!
            Sorry it was long before I answer back!
            • 3. Re: Use of application Item with conditional validation
              Louis-GuillaumeCarrier-Bédard
              Hi Amelie,

              You should consider centralizing your validations inside a package. It will make your code much more readable. In many cases, you won't have to modify your application to modify a validation.
              If your validations are required across different pages, consider having a main package or build package a package for each module (page or page groups).


              The following condition for a validation is easier to understand than "Value of Item in Expression 1 Is Contained within Colon Delimited List in Expression 2".

              Condition Type PL/SQL Expression:
              p1_valdt_pkg.is_item_mangm_mandt(:P1_ITEM_TYPE,:P1_ITEM_MANAGEMENT)



              create or replace function is_item_mangm_mandt (pva_item_type in varchar2,
              pva_item_mangm in varchar2)
              return boolean is
              vbo_valdt boolean default true;
              vva_const_business_case varchar2 (30) default v ('F126_CONST_BUSINESS_CASE');
              vva_const_proj_non_planifie varchar2 (30) default v ('F126_CONST_PROJ_NON_PLANIFIE');
              vva_const_proj_planifie varchar2 (30) default v ('F126_CONST_PROJ_PLANIFIE');
              begin
              if pva_item_mangm is null
              and pva_item_type in (vva_const_business_case, vva_const_proj_non_planifie, vva_const_proj_planifie) then
              vbo_valdt := false;
              end if;

              return vbo_valdt;
              exception
              when others then
              return false;
              end;



              Louis-Guillaume Carrier-Bédard
              -----
              My Blog: http://www.lgcarrier.com
              Twitter: http://www.twitter.com/lgcarrier
              APEX Québec: http://www.apexquebec.com
              APEXFramework: http://www.apexframework.com
              • 4. Re: Use of application Item with conditional validation
                Amelie
                Salut Louis-Guillaume!
                This is a good idea!
                Merci!