3 Replies Latest reply on May 15, 2013 7:30 AM by philmodjunk

    Else if script not working

    AppGuy

      Title

      Else if script not working

      Post

           I have a script trigger based on a checkbox value list.  The checkbox custom value is text.. For instance. "Red car"

            
           My script is basically.. If (table::field) ="red car"
            
           Then I have a few else if statements if the other values.  These values are all being stored in one field.
            
           The problem seems to be when I have multiple entries.  I am using the "or" statement in the text to ensure I am getting the right text.. For instance.. "Red car blue car" or "blue car red car".  This way no matter which one they pick 1 st it should still work..???  Any suggestions???  
            
           I have done the script debugger and it shows the right text but skips over the process.

        • 1. Re: Else if script not working
          philmodjunk

               The problem is in how multiple values are stored in that field when several boxes have been checked. If you were to make a copy of your field and change the formatting back to edit box for the copy. You'd be able to see what happens when several check boxes are clicked for that field. Each value is stored in the order in which the check box was clicked separated by a return character. If you selected the "Red Car" and "Blue Car" check boxes, you might have this in your field:

               Red Car
               Blue Car

               or you might have:

               Blue Car
               Red Car

               depending on which value was selected first.

               If you need a test to see if Red Car was selected, you can use this expression:

               Not IsEmpty ( FilterValues ( YourTable::CheckBoxField ; "Red Car" ) )

               If need a test to see if both red and blue car values were selected, you can use:

               ValueCount ( FilterValues ( YourTable::CheckBoxField ; List ( "Red Car" ; "Blue Car" ) ) = 2

          • 2. Re: Else if script not working
            ElishreeDey

                 Hi Jason

                 Hope this will help you.

                 In your application there is a checkbox having values e.g "Red Car", "Blue Car", "Black Car" and suppose you have selected Red Car and Blue Car from check box it will do something based on your selections from checkbox.
                  
                 So your If Else If Statement will be like as
                  
            If [PatternCount ( table::field ; "Red Car" ) > 0]
               Show Custom Dialog ["Message"; "Selected Red Car"]
            Else If [PatternCount ( table::field ; "Blue Car" ) > 0]
               Show Custom Dialog ["Message"; "Selected Blue Car"]
            Else If [PatternCount ( table::field; "Black Car" ) > 0]
               Show Custom Dialog ["Message"; "Selected Black Car"]
            Else
               Show Custom Dialog ["Message"; "Not selected any thing"]
            End If
                  
                      Or may be depending on your criteria you can modify If Else If Statement and will be like as
                       
            If [PatternCount ( table::field ; "Red Car" ) > 0 or PatternCount ( table::field ; "Blue Car" ) > 0]
               Show Custom Dialog ["Message"; "Selected either Red Car or Blue Car"]
            Else If [PatternCount ( table::field ; "Red Car" ) > 0 and PatternCount ( table::field ; "Blue Car" ) > 0]
               Show Custom Dialog ["Message"; "Selected Red Car and Blue Car"]
            Else If [PatternCount ( table::field ; "Black Car" ) > 0]
               Show Custom Dialog ["Message"; "Selected Black Car only"]
            Else
               Show Custom Dialog ["Message"; "Not selected any thing"]
            End If
                       
                  
                 Thanks Elishree
                 FileMaker 11 Certified Developer
                 Senior Software Engineer
                 MindfireSolutions
            • 3. Re: Else if script not working
              philmodjunk

                   Note:

                   PatternCount used in this context often works just fine but can fail to work correctly with certain value lists.

                   Example: If one value in your list is "Apple" and another "Applesauce", PatternCount ( CheckboxField ; "Apple" ) > 0 will be true if either of these two values are selected.

                   FilterValues avoids that potential complication.