bmill Posted January 8, 2015 Posted January 8, 2015 I have a DB for entering medical test results. Each patient has about 100 tests in five categories. To make data entry easier, I have a self-relating portal displaying the tests fields filtered by the five categories . A drop down menu with the list of test categories and script trigger sets the portal to display only tests in a category. If all results for a test category are the same , I want to to auto-enter the value chosen from a drop-down menu using a script trigger. The script loops through the visible portal setting the test-value in the result field if the test category matches the corresponding variable. This all works well enough but I cannot figure out how to stop the loop! There should be a simple solution but nothing I have tried keeps the loop from running endlessly. Any help would be appreciated. 1
bruceR Posted January 8, 2015 Posted January 8, 2015 When asking for help with a script that doesn't work, you will need to post the file; or at least the script. It really doesn't help matters to just say "I did something and it didn't work." 1
Kris M Posted January 8, 2015 Posted January 8, 2015 this is the normal loop script structure. LOOP do stuff EXIT LOOP IF (condition) do more stuff END LOOP If condition is never evaluates = 1 or greater than 1 then you have an endless loop.
Mark Scott Posted January 8, 2015 Posted January 8, 2015 Hi bmill, Agree with Bruce that having more to go on will "help us help you." That said… Looping through a portal can sometimes be problematic; some developers avoid it altogether. You are likely using a Go to Portal Row [next; exit after last] step and, if so, that may be where your problem lies. Various steps can cause FileMaker to exit the portal's focus and then it will keep going back to the same row (probably the first) and thus never exit. Try setting an explicit exit condition first and use that instead, something like: Set Variable [$exitCondition; /*some sort of exit condition based on count of related records shown in portal*/] Loop Exit Loop If [Let ( $i = $i + 1 ; $i > $exitCondtion )] Go to Object [Object Name: /*a field in portal*/] If [Get ( LastError ) = 116 /*Layout object is missing*/] Show Custom Dialog ["Layout Object Missing"; "The layout object such-and-such is missing. Script will now exit."] # Can remove this part once you're sure everything is working. Exit Script [] End If Go to Portal Row [Select; No dialog; $i] # Do stuff here End Loop The Exit Loop step, using a Let statement to both increment the counter and test for an exit condition, is a common technique in FileMaker, but you can split those into separate steps with a Set Variable step, if you prefer. Anyways, hth. Mark
Mark Scott Posted January 9, 2015 Posted January 9, 2015 Another thing to be cognizant of, bmill, when looping through portal rows is that if there is more than one portal on your layout, without diligence you may find yourself doing "stuff" in the wrong portal — could be benign or could be disastrous. As I mentioned, it's, at best, a technique to use sparingly and cautiously. hth, Mark
Rick Whitelaw Posted January 9, 2015 Posted January 9, 2015 If there are multiple portals on a layout, naming the destination portal object in the Inspector can obviate the issue.
Mark Scott Posted January 10, 2015 Posted January 10, 2015 Absolutely, Rick! And, possibly out of abundance of paranoia, after I "Go to Object," I then test for error 116 and provide myself an out if the named object is missing. Also, while I can't cite a specific case right at the moment, I've encountered instances where, after successfully going to a named object in the portal, something further down in the loop kicked me out. In addition to messing with a "go to next row—exit after last" construct, any sort of destructive action after that point ("Delete Portal Row"?) could act in the wrong place (or, hopefully, just fail gracefully if focus is not in a portal at all). Mark
bmill Posted January 10, 2015 Author Posted January 10, 2015 Perfect! Finally got it to work! Thank you all so much for the great help and insight. Brian
Recommended Posts
This topic is 3616 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now