Looping though a list of values

I am looking for an example script that loops through a list of values?? I had found the FileMaker article here: http://help.filemaker.com/app/answers/detail/a_id/2403

I was advised to avoid using the copy and paste script steps. Instead, I should capture the data into a script variable and set the result back to a field via the Set Field script step.

The article shows a way to use a loop to run through the records in a portal, and send the useful data to another field.

While it works, it seems to be inefficient. It's the only script in my solution that displays an hour glass while running.

If the list of values were in a field, how could I loop through them?

I have already determined that I'll need to use the ValueCount function instead of the Count function. I was staring at the screen for 15 minutes wondering why the Count function always returned 1.

I attached an image of the data I am working with.

Also is it possible to produce a found set out of the List? I see now after testing some more that the portal has a way to refer to a "Related Record" it can get there. I guess the way I imagined it could be further automated is missing something (probably cause of lack of knowledge ) the something being a way to get to each record in the appropriate layout and do something. In my case I just want to check a condition (via a checkbox) and if true add them to a join table.

Chris Johnston


To loop through a carriage delimited list of values (a list of values separated carriage returns), you have a few options.

First, as you correctly guessed, you'll want to capture the values into a script variable.

Second, using a few additional script variables and a loop, you can test each value one by one.

One of the most important script variables in this script is the$Counter variable. This variable is used to interact with each value (using the GetValue function). But most importantly, it is used to control the loop itself and prevent the loop from running forever (infinite loop). Grasp Learning Looping Exampl Script

In my example file, each crayon record has a list of characteristics. In a real-world solution, these characteristics would either be stored in a comma separated list or stored individually in their own record as related records.

Here's a screenshot of the example that I came up with: Grasp Learning Looping Example Screenshot

Download the example file here: FileMaker Loop Example.fmp12

Kevin Kurpe

Thanks again for all the help. Great example as usual.

This interesting your example lets me know that these loops can even be used for Text Parsing procedures. I did a little more research and produced a better script, I think. I say better because it works, no hourglass but don’t know if more in line with best practices.

Chris Johnston

Back to questions