Script: best solution or brute force ugliness?
I'm working on a script that will automatically add records to a table when a relationship is made. Specifically, we run an after school program where participants must sign consent forms and I'm adding a bit of functionality that can be used to keep track of which participants has signed what consent forms - groups within the program don't necessarily have to sign the same consent forms.
So, when a participant is added to a program's group the system will loop through the consent forms that are attached to that group and assign them to that participant. I also check to see if that participant has already signed that consent form - I loop through all of the records in the table that joins participants and consent forms to find an entry that matches the consent form ID and the participant ID. If a match is found I set a variable $Exists to 1 - in the next portion of the script I only add the record if $Exists = 0.
My question: is this the best way to do this? I've got a double loop - where the inner loop is going to loop through a join table that could potentially get quite large. This is likely how I'd write this if I were implementing this feature in something like php, but is this the best way to do it with filemaker? Is there some functionality or pattern I'm missing that would make this brute force approach more efficient?
I've attached a screen grab of my script.