6 Replies Latest reply on Jun 25, 2013 8:52 AM by philmodjunk

    Loop / If Statement



      Loop / If Statement


           I am trying to have the script go through my made up patients from Patients Table. One of the fields is "Treated?" which has a manual Yes / No objects to each patients, whether they are treated or not. And the script is supposed to sort the patients by many aspects, and one of them that I am working on is sorting them by "Treated?". However, after it sorts, I do not want the "Yes" patients to show up on the sorted list because I feel like this would be easier to look as a list. Below is the screenshot of what I attempted. The script does run without infinite loop or error. It DOES sort by Yes/No. But it does not omit "Yes" patients. Help would be appreciated!
           Thank you as always :) 


        • 1. Re: Loop / If Statement

               You don't need a loop to do this. You need a find.  You can perform a find to find records or Omit records.  

               1. ) Enter Find Mode  uncheck pause

               2. ) Set Field to Treated to "Yes"

               3. ) Omit Record

               4. ) Perform Find




               1.) Enter Find Mode  Uncheck pause

               2.) Set field to Treated to "No"

               3. Perform Find

          • 2. Re: Loop / If Statement

                 hahaha wow.. I was trying to do more work. Thank you! 

                 But is there a way to do it with a loop, from what I attempted?

            • 3. Re: Loop / If Statement

                   There is no reason to loop through all the records.  You can create a script to perform the steps I stated above.  Is there something else you are trying to accomplish?  

              • 4. Re: Loop / If Statement

                     No, not really. I was just trying to get used to the Loops and Ifs for Filemaker. I have used Java so I am familiar with the concept, but the two programs are different so I was trying to get to know it better. I guess my intention for using loops there was to see how to make the count variable increment by 1 each time it goes through the loop :)

                • 5. Re: Loop / If Statement

                       So thinking through your looping "learn" script...

                       You set a global to zero, then go to the zeroth record...?  Is there one?  How does the script work if you simply gotorecord [first] instead?

                       and inside the loop you go to record [next, exit after last] ?

                  • 6. Re: Loop / If Statement

                         Loops in FileMaker scripts take one of two forms:


                         Exit step (two choices exist)

                         End Loop

                         Is the commonly used format. Recursive script calls, however, can also produce a loop--either through perform script or by tripping a script trigger.

                         Your exit steps are either: Exit Loop If [boolean expression goes here, loop is exited if expression evaluates as true]

                         or: Go to Record/Request/Page [next ; exit after last] --> this step is used most often to loop through a set of records and automtically exit after the last record in the found set.

                         Here's an example that will loop 5 times:

                           //put the rest of your script code here
                            Set Variable [$K ; $K + 1 ]
                            Exit Loop If [ $K > 5 ]
                         End Loop

                         Note that this simple structure can replicate the for next, repeat until and while loops of more traditional programming languages simply by where you put the Exit step within the loop.