7 Replies Latest reply on Oct 11, 2016 8:00 AM by philmodjunk

    find script with multiple checkboxes

    madslp

      Hi,

       

      I'm trying to create a script to find records using checkboxes for several fields. A simplified version of my goal is to be able to find cars based on color and brand. I get this to work fine if only filtering based on one field, say finding all green and blue cars. I also manage to find the right records if I only use one criteria for each field, say green volvos.

       

      But I'd also like to constrain across fields, say by also ticking off volvo and audi, such that the found set would include blue or green volvos and blue and green audis. This is where I run into problems.

        • 1. Re: find script with multiple checkboxes
          David Moyer

          Hi,

          a few scripting notes:

          - set your $dep_ and $product_ variables before the first If, and use them in the If

          - the two subsequent Ifs should also reference the same $dep_ and $product_ variables

          - IsEmpty($i) will never be True in this setup

          (I'll keep looking at it.)

          1 of 1 people found this helpful
          • 2. Re: find script with multiple checkboxes
            Johan Hedman

            Depending on how many things you enable in your checkboxes you need to create one search record for each possible answers

             

            Car manufactor: Volvo, BMW

            Color: Blue, Silver

             

            Will need

            Search record 1

            Color Blue, Car Man. Volvo

            Search record 2

            Color Blue, Car Man. BMW

            Search record 3

            Color Silver, Car Man. Volvo

            Search record 5

            Color Silver, Car Man. BMW

            • 3. Re: find script with multiple checkboxes
              philmodjunk

              To build on Johan's response; These requests (we don't call them records to avoid confusion with actual records as you see them in Browse mode), can be generated with looping scripts with one loop nested inside the other so that for each value for color, you create one find request for each selected car brand.

               

              Global fields work well for this as your users can edit gobal fields to enter or select search criteria and then your script can enter find mode and still use the criteria in the global fields to set up the needed find requests.

               

              It's also possible to produce the same results by extending the found set instead of performing a find for each possible set of search criteria.

               

              For actual examples of both methods plus many more, see this thread of Scripted Find Examples.

              1 of 1 people found this helpful
              • 4. Re: find script with multiple checkboxes
                madslp

                Thanks to all of you for pointing me in the right direction. I'v read the thread with the scripted find examples, but have still not solved the problem of showing all combinations of ticked alternatives from two or more fields.

                 

                I've taken a step back trying to understand how the New Record/Request function works together with a nested loop to create a search record for each combination of values. Here's the code:

                 

                Enter Find Mode [ Pause: Off ]

                Set Variable [ $brands ; Value: List ( "Volvo", "BMW", "Audi") ]

                Set Variable [ $colors ; Value: List ( "Green", "Blue", "Red") ]

                Set Variable [$a ; Value: 1]

                Loop

                     Set Variable [ $i ; Value: 1]

                     Exit Loop If [ $a > ValueCount (brands) ]

                     Set Field [cars::Brand ; GetValue ( $brands ; $a) ]

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

                     Loop

                          Exit Loop If [ $i > ValueCount ( $colors) ]

                          Set Field [cars::Color ; GetValue ( $colors ; $i) ]

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

                          New Record/Request

                     End Loop

                End Loop

                Perform Find [ ]

                 

                This does almost what I want it to ( Find for each combination cars with brand AND color ). But looking at the Find Records I see that it searches for the combination only for the first occurrence of brand (top loop), and then searches only for the value in the (nested) color loop:

                Find records:     cars::Brand: [Volvo] AND cars::Color: [Green]

                Find records:     cars::Color: [Blue]

                Find records:     cars::Color: [Red]

                Find records:     cars::Brand: [BMW] AND cars::Color: [Green]

                Find records:     cars::Color: [Blue]

                Find records:     cars::Color: [Red]

                Find records:     cars::Brand: [Audi] AND cars::Color: [Green]

                Find records:     cars::Color: [Blue]

                Find records:     cars::Color: [Red]

                 

                Any ideas how to get the Find records look like this?:

                Find records:     cars::Brand: [Volvo] AND cars::Color: [Green]

                Find records:     cars::Brand: [Volvo] AND cars::Color: [Blue]

                Find records:     cars::Brand: [Volvo] AND cars::Color: [Red]

                Find records:     cars::Brand: [BMW] AND cars::Color: [Green]

                Find records:     cars::Brand: [BMW] AND cars::Color: [Blue]

                Find records:     cars::Brand: [BMW] AND cars::Color: [Red]

                Find records:     cars::Brand: [Audi] AND cars::Color: [Green]

                Find records:     cars::Brand: [Audi] AND cars::Color: [Blue]

                Find records:     cars::Brand: [Audi] AND cars::Color: [Red]

                 

                I hope/suspect that this is a simple error from my part, but I'm stuck, so would appreciate some more guidance.

                1 of 1 people found this helpful
                • 5. Re: find script with multiple checkboxes
                  David Moyer

                  Hi,

                  Try moving the line "Set Field [cars::Brand ; GetValue ( $brands ; $a) ]" to inside the inner loop.

                  Also, to handle new requests (without leaving an extra blank one at the end), try ...

                  set variable $firstRecord = 1

                  Loop

                    Loop

                      if $firstRecord = 1

                        set variable $firstRecord = 0

                      else

                        New Request

                      end if

                  ...

                  1 of 1 people found this helpful
                  • 6. Re: find script with multiple checkboxes
                    madslp

                    yes, that worked! thanks a lot!

                    • 7. Re: find script with multiple checkboxes
                      philmodjunk

                      When setting up multiple find requests it can also be useful at times to use duplicate Record/request instead of New Record/Request as a way to keep some criteria the same as the previous request before using Set field to add the part that's different in the new request.