1 2 3 Previous Next 31 Replies Latest reply on Aug 11, 2016 3:37 AM by PeterDoern

    How do I do a loop search of a given list of an attribute?

    ucharles

      Given a list of an attributes, is it possible to create script that would search my entire filemaker solution to find out if every content of that list is in my solution? How do I do it if is possible?

        • 1. Re: How do I do a loop search of a given list of an attribute?
          jim_smith

          Hi ucharles,

           

          I'm not sure I understood your question, but I'll give it a shot!

           

          My understanding of your situation:

          1. You have a list (multiple values separated by ).
          2. I'll refer to this as Search_List
          3. You wish to search for all records by a field.  If the record contains a value from the list, it should be found.
          4. I'll refer to this field as Table::Search_Field


          My solution:

          1. Create your script
          2. Exit script if Search_list has no values
          3. Set a variable $i = Valuecount ( Search_List )
          4. set a variable $k = 1
          5. Enter find mode.
          6. Create a loop
          7. Set Table::Search_Field to Getvalue ( Search_List ; $k )
          8. Exit Loop if $k = $i
          9. Set variable $k = $k +1
          10. Create a new request
          11. End Loop
          12. Perform Find

           

          Hope that works for you,

           

          Jim

          • 2. Re: How do I do a loop search of a given list of an attribute?
            erolst

            A bit streamlined:

             

            Set Variable [ $termCount ; Valuecount ( Search_List ) ]

            Enter Find Mode

            Loop

              Set Field [ Table::Search_Field ; GetValue ( Search_List ; Get ( RequestCount ) ) ]

              Exit Loop if [ Get ( RequestCount ) = $termCount ]

              New Request

            End Loop

            Set Error Capture [ on ]

            Perform Find

            • 3. Re: How do I do a loop search of a given list of an attribute?
              ucharles

              Thanks for your prompt response. You just sketched the my problem better than I could have done it myself. I  need some time to toy with script.

              • 4. Re: How do I do a loop search of a given list of an attribute?
                ucharles

                Erolst, pardon me for being dull-witted . Question: The "Search List" table must always be imported in FM, am I right? FM cannot do live comparison with an external file, isn't it?

                 

                I imported the "Search List" table"EMPLOYEES in FM, and then  wrote the script as advised.

                FM seems to be entering into an infinite loop that I can only terminate with esc (escape) key. I am getting strange results. Could you please diagnose what I am doing wrong and advice.

                • 5. Re: How do I do a loop search of a given list of an attribute?
                  erolst

                  ucharles wrote:

                  Question: The "Search List" table must always be imported in FM, am I right? FM cannot do live comparison with an external file, isn't it?

                   

                  It can absolutely!

                   

                  If you add an external file as “External Data Source”, you can for (almost) all intents and purposes treat the included tables as if they were in the current file itself – add table occurrences (TOs), create relationships, create layouts based on these TOs, read and write data. No need to import anything.

                   

                  So if you want to perform a search in a different FM file than the one where the script resides, just

                   

                  • add that file as external data source

                  • create a TO for the relevant table

                  • create a layout based on that TO

                  • perform your search in the context of that layout

                   

                  Basically, you can use the external file as a sort of data repository, and perform all interaction with that data in your “regular” file.

                  • 6. Re: How do I do a loop search of a given list of an attribute?
                    ucharles

                    Could you please see what I am doing wrong. Filemaker enters into permanent search when I run the script. Please diagnose the attached file. Use Admin, it doesn't have password. For some mysterious reasons it is requiring it is engaging "OnFirstWindowOpen" trigger.

                     

                    Set Variable.png

                    • 7. Re: How do I do a loop search of a given list of an attribute?
                      erolst

                      ucharles wrote:

                      For some mysterious reasons it is requiring it is engaging "OnFirstWindowOpen" trigger.

                      Mysterious forces at work … I doubt it.

                       

                      If you want to remove that trigger, go to File -> File Options, Script Trigger

                       

                      ucharles wrote:

                      Could you please see what I am doing wrong.

                       

                      Can't download your file ATM, but several things:

                       

                      1. Remove the pause option from the Enter Find Mode step

                       

                      2. Your script doesn't really implement what I suggested …

                       

                      Set Variable [ $criteriaList ; yourField ]

                      Set Variable [ $criteriaCount ; ValueCount ( $criteriaList ) ]

                      Enter Find Mode [ no pause ]

                      Loop

                        Set Field [ target field: yourField ; value: GetValue ( $searchList ; Get ( RequestCount ) ) ]

                        # [ there is no target field specified in your script ]

                        Exit Loop if [ Get ( RequestCount ) = $criteriaCount ]

                        # [ the above line was wrong – read my notes – causing the infinite loop ]

                        New Record/Request

                      End Loop

                      Set Error Capture [ on ]

                      Perform Find [ no restore ]

                       

                      Not sure why you need a looping script here – if you just want to find all record that have the same value in that field, use Find Matching Records; and if your field holds a list of values, then something else is not kosher. Anyway …

                       

                      When scripting (or coding in general, you can help yourself by giving variable appropriate names and checking if you are comparing the same things.

                       

                      A variable that holds text (also a list) shouldn't be called "count"; if you do, you run the risk of comparing different things –  someNumber = someText doesn't work.

                       

                      If you keep a (somewhat) consistent naming scheme, you know that you have to compare $xxxCount(er) with other $xxxCount(er)s – comparing $xxxCount with, say, $xxxList doesn't make sense.

                       

                      You may want to take some inspiration from the names of the built-in functions and their parameters.

                      • 8. Re: How do I do a loop search of a given list of an attribute?
                        ucharles

                        Thanks, I really had a long day filled with frustration. Enough for now, will try again in 6 hours.

                        • 9. Re: How do I do a loop search of a given list of an attribute?
                          ucharles

                          Can I use "Matching Records" function if I am using records from an external data source?

                          • 10. Re: How do I do a loop search of a given list of an attribute?
                            erolst

                            ucharles wrote:

                            Can I use "Matching Records" function if I am using records from an external data source?

                            Please read my above post carefully … (answer is yes)

                             

                            Apart from that, it doesn't seem a productive way for you to ask questions out of context, because that will only lead to more frustration. Maybe explain what you're trying to do, in what setup.

                            • 11. Re: How do I do a loop search of a given list of an attribute?
                              ucharles

                              Oops, I hope I am not about to become a nuisance by asking unproductive question   . Here is a background of what I am trying to do: farmers are buying ear tags to put on their livestock, they then complete a form to indicate which ear tags were put on which livestoc. That data is then captured on the national databas. My problem: a client wants to be able to determine which ear tags on his livestock are registered which a

                              • 12. Re: How do I do a loop search of a given list of an attribute?
                                ucharles

                                Dear Erolst, having cautioned earlier that I may be dull-witted, I beg for patience and courage. I may ask the dumbest of questions but please bear with me.

                                 

                                I want make sure I understand you correctly.

                                 

                                yourField = source field ≠ target field

                                targetField =is the field in the solution that I am comparing with external field (the sourceField)

                                 

                                if that is the case how do set the target field: "yourField'?  

                                 

                                Set Variable [ $criteriaList ; source field ≠ target field ]

                                Set Variable [ $criteriaCount ; ValueCount ( $criteriaList ) ]

                                Enter Find Mode [ no pause ]

                                Loop

                                  Set Field [ target field: yourField ; value: GetValue ( $searchList ; Get ( RequestCount ) ) ]

                                  # [ there is no target field specified in your script ]

                                  Exit Loop if [ Get ( RequestCount ) = $criteriaCount ]

                                  # [ the above line was wrong – read my notes – causing the infinite loop ]

                                  New Record/Request

                                End Loop

                                Set Error Capture [ on ]

                                Perform Find [ no restore ]

                                • 13. Re: How do I do a loop search of a given list of an attribute?
                                  erolst

                                  I would like us to be on the same page when we're talking about “external fields“.

                                   

                                  How many files – discrete FileMaker database files – does your solution comprise?

                                  • 14. Re: How do I do a loop search of a given list of an attribute?
                                    ucharles

                                    Let's assume we have two files: one file is an excel file and a filemaker file. The excel file has a table or worksheet that has the "same" attributes  as one of the tables in filemaker file. The excel file is the external source. However, I am, for all intents and purposes interested in using only one attribute, that is in both excel  and filemaker files to find out the discrepancy in the records of both files, at least with respect to the alone.

                                    1 2 3 Previous Next