4 Replies Latest reply on May 19, 2015 9:53 AM by SteveMartino

    OnObjectValidate calculation trouble

    LauraJones

      Title

      OnObjectValidate calculation trouble

      Post

      Hi, 

      I am trying to create validations for several of my fields and decided to use the OnObjectValidate option. The script seems to work, I use the "If" function to write a calculation with my validations and then if false, the field is cleared and a message appears. All the steps seem to work but only half of the validations within the calculation seem to work correctly. This is the calculation:

      Not (Infant Demographics Record Sheet::Mean blood pressure = "[ND]" or IsEmpty (Infant Demographics Record Sheet::Mean blood pressure) or Length ( Infant Demographics Record Sheet::Mean blood pressure )  ≤  2  and ( Filter ( Infant Demographics Record Sheet::Mean blood pressure ; "9876543210" ) ) and Infant Demographics Record Sheet::Mean blood pressure   <  81 and Infant Demographics Record Sheet::Mean blood pressure   >  4)

      When the field is empty or says [ND] everything works fine but it will only let me enter values 5-8 and 40-81. Why is there a section of values it won't allow? 

        • 1. Re: OnObjectValidate calculation trouble
          SteveMartino

          Quite a confusing calculation which could be written easier if I (we) understood what you were trying to accomplish.  I assume the calculation is set as text for the ND result, but is tripping up because of the numbers.  And this is a single If function?

          Not (Infant Demographics Record Sheet::Mean blood pressure = "[ND]"

          or IsEmpty (Infant Demographics Record Sheet::Mean blood pressure)

          or Length ( Infant Demographics Record Sheet::Mean blood pressure )  ≤  2  and ( Filter ( Infant Demographics Record Sheet::Mean blood pressure ; "9876543210" ) ) and Infant Demographics Record Sheet::Mean blood pressure   <  81 and Infant Demographics Record Sheet::Mean blood pressure   >  4)  This one is confusing.  The length is less then or equal to 2 AND it contains only numbers AND its less then 81 AND its greater then 4?

          I don't see anything about if the validation fails you clear the field and get a message.  Can you also post the entire script/calc?

          • 2. Re: OnObjectValidate calculation trouble
            philmodjunk

            I suspect that this is a text field when it should either be a number field or your expressions that compare numeric values should enclose the field inside GetAsNumber so that they evaluate as numbers and not text during the comparison.

            Text when comparing a number in a text field, "2" > "1000" is a true statement

            • 3. Re: OnObjectValidate calculation trouble
              LauraJones

              I've made the calculation more simple and one thing I need to point out is that I have the same script and calculation for several fields but half of them work and the other half give me this problem. The only differences between each script are the numbers used as the allowed range. So the whole script for this one is:

              If [not (Infant Demographics Record Sheet::Mean blood pressure = "[ND]"

              or IsEmpty (Infant Demographics Record Sheet::Mean blood pressure)

              or Infant Demographics Record Sheet::Mean blood pressure  ≥ 5 and  Infant Demographics Record Sheet::Mean blood pressure  ≤ 80)

              ]

              Clear [select; Infant Demographics Record Sheet::Mean blood pressure]

              show custom dialog ["must be a value between 5 and 80 or [ND]"]

              End If

              This allows the field to contain [ND] or be empty but only allows certain numbers. If it was an issue with not bringing back numbers because of the [ND] then wouldn't that stop all numbers from being entered and not just a select few? I've tried writing the numbers as "5" and "80" but that doesn't make a difference. Also I still don't understand why some of the fields are working fine. They are all text fields in order to allow for [ND]. 

              • 4. Re: OnObjectValidate calculation trouble
                SteveMartino

                Follow Phil's suggestion, and hopefully you have advanced, do the following:

                Disable the script trigger/calculation and put the expression in the data viewer and test it (in the data viewer).  You can actually put them as 3 separate equations to see which ones are evaluating as true 1 or false 0.  You may need to refresh on the data viewer if it isn't changing.

                Equation 1:

                not (Infant Demographics Record Sheet::Mean blood pressure) = "[ND]"

                Equation 2:

                IsEmpty (Infant Demographics Record Sheet::Mean blood pressure)

                Equation 3:

                GetAsNumber(Infant Demographics Record Sheet::Mean blood pressure) ≥ 5 and  GetAsNumber(Infant Demographics Record Sheet::Mean blood pressure)  ≤ 80

                Then start putting the correct/incorrect values in, and check the data viewer for the results.  Once again you may have to refresh the data viewer. 

                I also recommend you do this on a copy of the database.