Jump to content

Help scripting in portal


bmill
 Share

This topic is 2883 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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. 

  • Like 1
Link to comment
Share on other sites

 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."

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 2883 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.