3 Replies Latest reply on Oct 6, 2011 3:38 PM by philmodjunk

    scripting a multiple find request

    SarahCarroll

      Title

      scripting a multiple find request

      Post

      I am new to scripting in FMP.  I have version 9, if that makes a difference. 

      1. I want to create a script that finds all records where the "Grade" field contains one of a set of values (C+, C, C-, D, F, NC, I).  I'm sure this is incredibly easy, and I know how to do it "live", but I cannot figure out how to make it happen in a script.

      2. Is there a way to have ScriptMaker "record" what I'm doing and generate a script that I can then edit?

      Thank you!

        • 1. Re: scripting a multiple find request
          philmodjunk

          There isn't a "macro recorder" feature in FileMaker. Your most recent sort order and find criteria are accessible, but I'd prefer to spell out the details in specific script steps as that makes for a script where it's much easier to figure out what it does when you go back and look at it a month from now.

          I don't know from your post whether you want a script that always finds records with the same list of criteria or if the user will select from a list and then the script uses those choices to find records. I will assume that the user selects values in a checkbox field and then you need to use those choices as your search criteria.

          Give you check box field the global storage field option. I'll assume that it is called: YourTable::gGradeList. Then this script will generate one finde request for each selected value in that field:

          Enter Find Mode[] //clear the pause check box
          Loop
             Set Variable [$I ; Value: $I + 1 ]
             Set Field [YourTable::Grade ; Getvalue ( YourTable::gGradeList ; $I ) ]
             Exit Loop If [$I > ValueCount ( YourTable::gGradeList ) ]
             New Record/Request
          End Loop
          Set Error capture [on]
          Perform Find []

          • 2. Re: scripting a multiple find request
            SarahCarroll

            Thank you for that quick and thorough response!  I have not yet used global fields, so for the moment I just  want to hard-code the list of values.  This will be a canned thing that I run a couple of times a semester.  I'm guessing that will simplify the script...?

            • 3. Re: scripting a multiple find request
              philmodjunk

              Actually the script is nearly the same.

              Here's a "canned list" example:

              Set Variable [$GradeList ; value: List ( "C+"; "C"; "C-"; "D"; "F"; "NC"; "I" ) ]
              Enter Find Mode[] //clear the pause check box
              Loop
                 Set Variable [$I ; Value: $I + 1 ]
                 Set Field [YourTable::Grade ; "=" & Getvalue ( $GradeList ; $I ) ]
                 Exit Loop If [$I > ValueCount ( $GradeList ) ]
                 New Record/Request
              End Loop
              Set Error capture [on]
              Perform Find []