4 Replies Latest reply: Jul 3, 2013 4:58 PM by Howard (... in Training) RSS

    Validation script on multiple page items

    NewApexCoder

      Apex 4.2

       

      I'm havin trouble figuring out how to validate against multiple fields

       

      I have a form that has a text field (P32_REQUESTOR). I have created a validation that returns an error if this field is left blank or not filled in by the user

       

      Type: Item / Column specified is NOT NULL

      Validation Expression 1: P32_REQUETOR

       

      I have recently added a another page item to the form (P32_POC) where I want the same validation to happen as well

       

      So if P32_REQUESTOR and P32_POC are left blank, then an error is raised. I am just not sure on how to accomplish this or if a pl / sql statement is needed or if you can add multiple items to the 'Validation Expression 1' area.

       

      At a stand still. Any help would be greatly appreciated. Thanks in advance.

        • 1. Re: Validation script on multiple page items
          Howard (... in Training)

          Testing on APEX 4.2, I see that validations are related to individual fields, so you can't do fancy ":P32_SAL > 10000 AND :P32_COMM < 500" validations.  But let me understand, you need P32_REQUE(S?)TOR not null and P32_POC not null?  Right?  If so, you just need to separarte validations, one for each. Otherwise you have more cases to test: 1st one is null and not the other, 2nd one is null and not the other, ...

           

          It only gets complicated if you want three different error messages, one for each and a different message if both are null.

           

          Does that answer the question?

          Regards,

          Howard

          • 2. Re: Validation script on multiple page items
            NewApexCoder

            @Howard

             

            Yes this is helpful. I wasn't sure if using separate validations for each one would work. I had tried something similar to multiple validations before but it didn't pan out too well. I will try it again and post the code if neccessary later on. But yes I need to check against the two basic cases:

             

            Case_1     P32_REQUESTOR IS NOT NULL AND P32_POC IS NOT NULL

            Case_2     P32_REQUESTOR IS NULL AND P32_POC IS NULL

            So in the event that either Case_1 or Case_2 happens, There would be a generic error message that covers both cases. Something along the lines of:

             

            Error: You must either fill in informaton for the Requestor OR the POC.

            • 3. Re: Validation script on multiple page items
              fac586

              Howard(...inTraining) wrote:

               

              Testing on APEX 4.2, I see that validations are related to individual fields, so you can't do fancy ":P32_SAL > 10000 AND :P32_COMM < 500" validations.

              Of course you can. Use a page level validation of type PL/SQL Expression:

               

              :P32_SAL > 10000 AND :P32_COMM < 500

               

              But let me understand, you need P32_REQUE(S?)TOR not null and P32_POC not null?  Right?  If so, you just need to separarte validations, one for each.

              Indeed. An item level not null validation on each item is the way to go.

              • 4. Re: Validation script on multiple page items
                Howard (... in Training)

                Okay.  As per fac586, then a single page level validation should do this -- with proper use of parenthesis.

                In the validation GUI, pick page on the first screen.  Now I might try using "PL/SQL Function Returning Error Text"

                 

                PL/SQL Function Returning Error Text Example

                if (your compound condition goes here) then return 'Error: You must either fill in information for the Requestor OR the POC.'; else return null; end if; 

                 

                Or something close to that.