11 Replies Latest reply on Aug 9, 2010 1:41 PM by jgaglio

    Find records using a global field

    jgaglio

      Title

      Find records using a global field

      Post

      I want to do a scripted find using a global field with values for a music file I'm creating. There are 12 music genre values ie. Jazz, Rock, Funk, Pop etc.. User will select the genre by check box (value list) then select a search button, the result will be a list of songs by genre. Here's what I have so far, but it's not working.

      • Enter Find Mode [ ]
      • If [ Document Library::gGenre > 1 ]
      • Set Variable [ $values; Value:"Document Library::gGenre" ]
      • Loop
      • Set Field [ Document Library::Genre; LeftValues ( $values ;1 ) ]
      • Set Variable [ $values; Value:RightValues ($values ; ValueCount ($values )-1 ) ]
      • Exit Loop If [ IsEmpty ( $values ) ]
      • Duplicate Record/Request
      • End Loop
      • End If
      • Constrain Found Set [ ]
      • Enter Browse Mode

      Screen_shot_2010-08-05_at_12.56.52_AM.png

        • 1. Re: Find records using a global field
          sunmoonstar.13

          Seems more complicated than you need. Maybe try this instead:

          (1) Create a layout in List View based on the Songs table

          (2) Put your gGenre checkbox field and search button in the Header part of the Layout

          (3) Attach the following script to your search button:

          Set Variable [ $values; Value:"Document Library::gGenre" ]
          If [ IsEmpty ($values) ]
              Show All Records
              Exit Script
          End I
          Perform Find [Restore] // Field: Document Library::gGenre     Criteria: $values

           
          Now, whenever you check one or more checkboxes, then click the search button, the list will update with a found set. For example, if you check "blues" it will find all the blues songs. If you check "blues" and "jazz", it will find all the songs that have been categorised as blues AND jazz.

          If you have FMP 10 or 11, you can omit the search button and set gGenre with a Script Trigger (onObjectModify) so everytime you check/uncheck a checkbox, the llist updates with a new found set.

          You might also want to build an error capture into your script in case the Find results in "No matching records"

           

          Nick

           

          1 of 1 people found this helpful
          • 2. Re: Find records using a global field
            sunmoonstar.13

            Apologies, I meant to write the following in the last step of the script:

            Perform Find [Restore] // Field: Document Library::Genre     Criteria: $values

             

            Nick

            • 3. Re: Find records using a global field
              LaRetta_1

              A small clarification (because it is important when understanding the difference between performing finds using AND or OR) ...

              Nick said, "If you check "blues" and "jazz", it will find all the songs that have been categorised as blues AND jazz."

              Nick had it right (and I know he understands this) but the word AND should be OR as in:

              "If you check "blues" and "jazz", it will find all the songs that have been categorised as blues OR jazz."

              • 4. Re: Find records using a global field
                philmodjunk

                Perform Find [Restore] // Field: Document Library::Genre     Criteria: $values

                Since you are using set field to build your stack of requests to get an OR based find as LaRetta explains, you shouldn't use the restore option here, just Find [].

                • 5. Re: Find records using a global field
                  jgaglio

                  Nick,

                  I am using FM 11 and I like the idea of having a find work dynamically as you mention using a script trigger. However, I am new to the trigger function and can't seem to get your script to work. Any suggestions? 

                  • 6. Re: Find records using a global field
                    sunmoonstar.13

                    Right-click your gGenre field, click "Set Script Triggers", select onObjectModify, then select the relevant script and click OK.

                    Nick

                    • 7. Re: Find records using a global field
                      jgaglio

                      Nick,

                      Script still not working:

                      • Enter Find Mode [ ]
                      • Set Variable [ $genreValues; Value:Document Library::gGenre ]
                      • If [ IsEmpty ( $values ) ]
                      • Show All Records
                      • Exit Script [ ]
                      • End If
                      • Perform Find [ ]

                      Is the variable supposed to reflect the the values from "Genre" or the global "gGenra"? I tried both either way.

                      Thanks.

                      • 8. Re: Find records using a global field
                        OwenKlingdon

                        I think the issue is that your set variable is $genreValues and the logic test in the next line is called $values so because it fails it shows all the records in the next line and doesn't get to the find part.

                        • 9. Re: Find records using a global field
                          jgaglio

                          Actually, I did change it to read $genreValues, I just posted a copy and paste before I made the change. Still doesn't work.

                          • 10. Re: Find records using a global field
                            philmodjunk

                            I don't see anything in your last script that enters any find criteria. I'd expect to see a set field step after the enter find mode step that actually enters some criteria from a global field before performing the find.

                            I haven't tested it, so am wondering if Show All records will work as expected unless you first return to browse mode as most script steps treat records as "requests" when you are in find mode.

                            • 11. Re: Find records using a global field
                              jgaglio

                              I got it to work. I had a fw lines missing, see below:

                              • Enter Find Mode [ ]
                              • If [ ValueCount (Document Library::g_Genre>1 ) ]
                              • Set Variable [ $values; Value:Document Library::g_Genre ]
                              • Loop
                              • Set Field [ Document Library::Genre; LeftValues ( $values ;1 ) ]
                              • Set Variable [ $values; Value:RightValues ($values ; ValueCount ($values )-1 ) ]
                              • Exit Loop If [ IsEmpty ( $values ) ]
                              • Duplicate Record/Request
                              • End Loop
                              • End If
                              • Perform Find [ ]