5 Replies Latest reply on Dec 22, 2015 11:00 AM by WilliamMartin_1

    Using checkboxes with IF

    WilliamMartin_1

      Hello all,

       

      I'm trying to write a script that will check the values of a checkbox set and perform an action based on the contents of the checkbox set.

      Here's a sample of what I had written. This does not work as intended but it will hopefully outline what I'm trying to accomplish.

      The idea for this sample script is to set another field to either "1" "2" "3" or "4" based on the results of the test.

       

      If [ (Table::CheckboxSet = "Box A" & "Box B" & "Box C") & (Table::AnotherField = "Desired Value One") ]

           Set Field [ Table::TestResult ; 1 ]

      Else If [ (Table::CheckboxSet ≠ "BoxA" & "Box B" & "Box C") & (Table::AnotherField = "Desired Value One") ]

           Set Field [Table::TestResult ; 2]

      Else If [ (Table::CheckboxSet = "Box A" & "Box B" & "Box C") & (Table::AnotherField = "Desired Value Two") ]

           Set Field [ Table::TestResult ; 3 ]

      Else If [ (Table::CheckboxSet ≠ "BoxA" & "Box B" & "Box C") & (Table::AnotherField = "Desired Value Two") ]

           Set Field [Table::TestResult ; 4]

       

      Thanks in advance!

       

      William

        • 1. Re: Using checkboxes with IF
          Extensitech

          If [ ( ValueCount ( FilterValues ( Table::CheckboxSet "Box A¶Box B¶Box C") ) = 3... etc.

           

          Because "BoxA" & "Box B" & "Box C" = "BoxABox BBox C", and even if you inserted the return characters, the values in CheckBoxSet are in the order the user clicked them, not the order of your value list.

           

          Instead, use FilterValues to determine what values in your test set are in the CheckBoxSet, and see if all three are there.

           

          Does this make sense to you? Will it work for you?

           

          Chris Cain

          Extensitech

          • 2. Re: Using checkboxes with IF
            Mike_Mitchell

            Hello, William. There's a basic behavior in checkbox sets that will affect your outcome, and is likely what's causing the malfunction. Checkbox sets are stored in FileMaker as return delimited lists. For example, if you choose Box A and Box B, the result will look like this:

             

            Box A

            Box B

             

            Additionally, the values appear in the order the user selected them, so if he chose Box A, then Box C, then Box B, you'd get:

             

            Box A

            Box C

            Box B

             

            So, in order to determine if your desired pattern is present, you can't use Box A & Box B & Box C for both reasons: First, the values are in a list, not a string, so your "=" won't match, and second, they could appear in any order.

             

            What to do? Use the FilterValues function to determine if your values are present. For example:

             

                 If [ ValueCount ( FilterValues ( Table::CheckboxSet ; "Box A¶Box B¶Box C )) = 3 ]

                      // All three values selected

                 End If

             

            The various Value functions (GetValue, LeftValues, MiddleValues, RightValues, FilterValues) are invaluable to learn.

             

            HTH

             

            Mike

            • 3. Re: Using checkboxes with IF
              Mike_Mitchell

              Darn that refresh ...  

              • 4. Re: Using checkboxes with IF
                Extensitech

                First! LOL.

                 

                We should've picked shifts today.

                 

                Chris Cain

                Extensitech

                • 5. Re: Using checkboxes with IF
                  WilliamMartin_1

                  Thank you Chris & Mike! I revised my script as you suggested and it worked exactly how I expected.