12 Replies Latest reply on Aug 28, 2015 9:26 PM by BruceRobertson

    Find based on yes no selection

    g4guitar

      Is there a way to set up a find allowing me to switch on and off certain selections?

       

      Example. I have a timetable and I want to look only for certain days of the week. I don't want to be manually typing in the different day combinations each time. Ideally I want an on/off switch for each day. So if I want to see Tuesdays and Thursdays only I want to click buttons for those days to an 'on' (show) setting while the other days are set to off (hide). If I want to add Wednesday I just to switch on Wednesday. Its like having a house with 7 rooms. I want to be able to switch lights on and off in each room as needed. Any help would be greatly appreciated. Thank you.

       

      Screen Shot 2015-08-25 at 4.44.33 pm.png

        • 1. Re: Find based on yes no selection
          shwetam@metasyssoftware.com

          I can think of 2 ways to do this.

           

          1. Create a global field and attach a valuelist of days to it. This field will have have selected values separated by return key. Write a script to loop through the values and create a find request for each iteration of loop. Then perform find.

           

          2. Create a global field and attach a valuelist of days to it. Create a relationship between this field to the days field. The second table occurrence will have the related foundset. You can use GTRR to go to the foundset.

           

          Hope this helps.

          • 2. Re: Find based on yes no selection
            keywords

            It depends what you mean by "look only for certain days of the week". If you only want to view the selected day(s) on screen a portal might do, which you could use to display only the selected day(s) of the week via a relationship based on a global field (as suggested already).

            • 3. Re: Find based on yes no selection
              Mike_Mitchell

              keywords is correct. We need more information to answer the question correctly. If you want to filter a portal, then shwetam's answer would be a good one. On the other hand, if you're trying to locate records in a Form or List view, then you would want to build a script (possibly with an accompanying Script Trigger) that would loop over the list of selections, create a Find request for each one, and then perform the requisite Find (with traps for an empty found set).

              • 4. Re: Find based on yes no selection
                g4guitar

                Thank you shwetam,

                 

                I understand  '1. Create a global field and attach a valuelist of days to it. This field will have have selected values separated by return key.


                I am not sure about 'Write a script to loop through the values and create a find request for each iteration of loop. Then perform find.' - How would I write this script?


                Thank you.

                • 5. Re: Find based on yes no selection
                  g4guitar

                  Thank you keywords,

                   

                  In short I have a list of days and time on a Layout list view. No portal involved at this point. I want to be able to choose to find only certain days E.g. Tue and Thu without doing two separate find. Sorry if I am not explaining clearly but this is basically all I want to be able to do.

                   

                  Thanks again.

                  • 6. Re: Find based on yes no selection
                    mark_scott

                    g4guitar,

                     

                    When you say "e.g., Tue and Wed," I'm reading this to mean a Boolean "OR" search, correct?  That is, find all records where day is either Tuesday OR Wednesday, thus creating a union of those two sets of records.  Do I have this correct?  If so, then the way — not the only one as shwetam has already offered a great alternative in the form of GTRR — to do a Boolean OR search on a single field in FileMaker is with multiple Find Requests.  I suspect that the multiple-request aspect might be your stumbling block here; if so, then check this Help page out.  If you script the process, then the relevant step is "New Record/Request," which, in Find mode, creates a 2nd (or more) find request, rather than a new record.

                     

                    hth,

                     

                    Mark

                    • 7. Re: Find based on yes no selection
                      g4guitar

                      Thank you Mark,

                       

                      Your advice is getting me closer. Yes its a Boolean 'OR' find request because I want to be able to see all records that are on selected days based on a checkbox field. In the example below I have checked Mon and Wed and want to be able to click a button that will return me a list of all the Mon and Wed records. What I am still stuck on is how I can have say a checkbox of the days of the week, select the days I want and then have the find script look up the days I have checked and give me a list of only those days. The pic below shows how I want it to work. Thank you again for your help. Its greatly appreciated.123.png

                      • 8. Re: Find based on yes no selection
                        Mike_Mitchell

                        Set Variable [ $count ; 1 ]

                        Enter Find Mode

                        Loop

                             Set Field [ Day ; GetValue ( DayOfWeek ; $count ) ]

                             Exit Loop If [ Let ( $count = $count + 1 ; $count > ValueCount ( DayOfWeek )) ]

                             New Record / Request

                        End Loop

                        Set Error Capture [ On ]

                        Perform Find [ ]

                        Set Error Capture [ Off ]

                        If [ Get ( FoundCount ) < 1 ]

                             Show All Records

                        End If

                        Sort Records [ {your preferred sort here} ]

                         

                        HTH

                         

                        Mike

                        • 9. Re: Find based on yes no selection
                          erolst

                          Mike_Mitchell wrote:

                          Set Variable [ $count ; 1 ]

                          Enter Find Mode

                          Loop

                              Set Field [ Day ; GetValue ( DayOfWeek ; $count ) ]

                              Exit Loop If [ Let ( $count = $count + 1 ; $count > ValueCount ( DayOfWeek )) ]

                           

                          Since you perform a Find, you could

                           

                          Set Variable [ $count ; 1 ]

                          Enter Find Mode

                          Loop

                              Set Field [ Day ; GetValue ( DayOfWeek ; Get ( RequestCount ) ) ]

                              Exit Loop If [ Get ( RequestCount ) = ValueCount ( DayOfWeek )) ]

                               New Record/Request

                          End Loop

                          Perform Find

                           

                          Just sayin …'

                          • 10. Re: Find based on yes no selection
                            g4guitar

                            Thank you Mike and erolst,

                             

                            I think I need to study this a little more. I have tried putting the code you both suggest but no joy. I doesn't do anything. realist's suggestion causes the program to get stuck in loop mode. I know I am missing something here but not sure what. Here is what I did below. Good news is I have worked out a work around until I understand coding better. Thanks again. 123444.png

                            • 11. Re: Find based on yes no selection
                              mark_scott

                              I think one problem might be that if you run this loop with no values checked in the DayOfWeek field, then it won't exit because the RequestCount (which starts at 1 and then increments by 1 with each iteration) will never equal ValueCount( DayOfWeek ), which is zero in this scenario.

                               

                              They something like:

                               

                              Set Variable [ $daysChecked ; ValueCount ( DayOfWeek ) ]

                              Enter Find Mode

                              Loop

                                   Exit Loop If [ Get ( RequestCount ) > $daysChecked ]

                                   Set Field [ Class::Day ; GetValue ( DayOfWeek ; Get ( RequestCount ) ]

                                   New Record/Request

                              End Loop

                              Perform Find [ ]

                               

                              It's mostly just personal preference, but I like to set my exit condition ("ValueCount( DayOfWeek )" in this case) into a variable before the loop starts.  Probably not necessary here, but a handy habit when looping through records (where "Exit After Last" will generate an error), or looping through a portal, where portal-row focus can be inadvertently lost and cause the looping to go awry. 

                               

                              The other thing I Iike to do, which is really the key change I've made here, is to put my Exit Loop If step at the top of the loop, before any "business" code, so that the loop can exit immediately if the exit condition is met (as would be the case where there are no checked values in the DayOfWeek field).

                               

                              hth,

                               

                              Mark

                              • 12. Re: Find based on yes no selection
                                BruceRobertson

                                A suggested mod to Mark's example script:

                                 

                                Set Variable [ $daysChecked ; ValueCount ( DayOfWeek ) ]

                                IF [ $daysChecked > 0 ]

                                  Enter Find Mode

                                  Loop

                                     Exit Loop If [ Get ( RequestCount ) > $daysChecked ]

                                     Set Field [ Class::Day ; GetValue ( DayOfWeek ; Get ( RequestCount ) ]

                                     New Record/Request

                                  End Loop

                                  Perform Find [ ]

                                Else

                                  Beep

                                End If