Title
Looping through Found Sets
Post
My question relates to the outline of a script suggested here to help divide my database into random cohorts of 1/12 total records.
http://forums.filemaker.com/posts/35570589c1?commentId=295871#295871
Records in my table are assigned one of 8 Categories (text field) and 6 sub-categories (calculation number result). I want to perform a repetitive function on each of the 48 combinations but I'm not sure how to structure the loop in the script step.
Steps in the Script
- Find Category 1 AND sub-category 1, perform function
- Find Category 1 AND sub-category 2, perform function
- Find Category 1 AND sub-category 3, perform function
- etc.
Repeating this for a total of 48 combinations of category and sub-categories seems tedious and like an ideal situation for a Loop.
Is there a way to create a looping process to go through all 48 combinations without having to copy / paste every combination in a script that steps through each in sequence?
While many of the examples use a global field, you probably do not need one in your case. The global fields in those examples are used as a way for a user to manually select/enter search criteria while in Browse Mode that a script can then access while in Find Mode in order to set up search criteria.
In your case, there's no user inputting the search criteria so you don't need the global field. That's why my example used a calculation with a list function instead of a global field reference.
Set Variable [$FruitList ; value: List ( "Apple" ; "Strawberry" ; "Grape" ; "Peach" ) ]
Set Variable [$Sources ; value: List ( "Imported" ; "Local" )
Set Error Capture [on]
Loop
Set Variable [$J ; $J + 1 ]
Exit Loop If [ $J > ValueCount ( $Sources ) ]
Set Variable [$K ; value ; 0 ]
Loop
Set Variable [$K ; Value: $K + 1 ]
Exit Loop If [ $K > valueCount ( $FruitList ) ]
Enter Find Mode []
Set Field [YourTable::Fruit ; GetValue ( $FruitList ; $K) ]
Set Field [YOurTable::Source ; GetValue ( $Sources ; $J ) ]
Perform Find[]
Put code here to process the found set produced by this find.
End Loop
End Loop