6 Replies Latest reply on May 11, 2015 8:49 AM by lijnbach

    Search based on Values in Checkbox

    lijnbach

      Title

      Search based on Values in Checkbox

      Post

      Hello everybody,

       

      I use a checkbox to store the values chosen by the user. It is not complicated and it are just 4 values. (Computer  -  Concrete - E-Book - Internet). The user can choose one value, more values or all values, whatever they like, in the pick order they like.

      The chosen values are stored and sorted in a global field for later use.

       

      Later on there is a search (using “Find” - “SetField” - “Perform Find”) based on values in the global field.

      In the SetField is use “from - until”:

       

      SetField [LearningMaterial ; GetValue ( gField::MateriaI ; 1 ) & ".."  &  GetValue ( gField::Material ; ValueCount (gField::MateriaI ) )]

       

      (The field “gField::Material” is sorted for a proper find)

       

      But now comes the problem;

      If a user only checked “Computer” and “Internet” I can’t use the “from - until” option, because FM takes everything between “Computer” and “Internet” and I only want a search for the checked values.

       

      I think I am making a “thinking mistake”, but I can’t find a proper solution to perform a search based on the checked options. I solved it now by counting the number of values in the checkbox and use “if” to check the quantity of values. But that seems not an proper or elegant solution.

       

      Anybody a good idea?

       

      Thanks in advance.

       

      Hans Lijnbach.

        • 1. Re: Search based on Values in Checkbox
          FentonJones

          This is a fairly simple method to do a Find, with multiple values (in a return separated list). [ The trouble with a normal Find of such is that FileMaker sees them as a "AND" search, not an "OR" search.] The below script does it much the same as you'd do a manual Find, i.e., adding a new Request for each new value.

          It will produce an error if nothing is found, same as a manual Find. You could use Set Error Capture [ On ], and deal with it. But that is not real simple, and another post :-|

          I used my own generic names for the fields, etc.. But there's only 2 fields, a global, and the regular field (near the end). It is mostly some simple Variables ( make sure each instance is named the same ):

          Set Variable [ $values; Value:Textual::_gValues ]

          Set Variable [ $values_cnt; Value:ValueCount ( $values ) ]

          Enter Find Mode [ ]

          Loop

              Set Variable [ $num; Value:$num + 1 ] 

              Exit Loop If [ $num > $values_cnt ]

              Set Field [ Textual::Data; GetValue ( $values; $num ) ]

              New Record/Request 

          End Loop

          Perform Find [ ]

           // or: Constrain Found Set [ ]

           

          [ Modified slightly, to make it even simpler.]

          • 2. Re: Search based on Values in Checkbox
            lijnbach

            Thanks for your time and effort Fenton,

            You are right, the problem with a normal find is that FM sees them as an "AND" search and not an "OR" search. I have found a work around. If a user checkes a value, the value is shown in the field. I have a second hidden field, that does the opposite. If a user checkes a value, the value is unchecked in the hidden field. At the end of the (extensive) search I perform finds and "omit" the records of the values in the hidden field. 

            But your solution is more elegant and less work, it looks logical and it is working. (And I didn't think of using a loop). I will implement your solution. (It is just a part of a very extensive selection).

            Thanks again Fenton,

            Hans Lijnbach

             

            • 3. Re: Search based on Values in Checkbox
              philmodjunk

              You might find this thread of scripted find examples helpful.

              It includes an "Or" find based on the values selected in a check box.

              • 4. Re: Search based on Values in Checkbox
                lijnbach

                Thanks like always Phil,

                But can you include a link to the thread?

                Hans Lijnbach

                • 5. Re: Search based on Values in Checkbox
                  philmodjunk

                  Sorry, brains is still "caffeine deficient"

                  Scripted Find Examples

                  • 6. Re: Search based on Values in Checkbox
                    lijnbach

                    Thanks Phil,

                    This helpful.

                    Hans Lijnbach