Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help scripting in portal

Featured Replies

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. 

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

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.

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

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

If there are multiple portals on a layout, naming the destination portal object in the Inspector can obviate the issue.

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

  • Author

Perfect!   Finally got it to work!

 

Thank you all so much for the great help and insight. 

 

Brian

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.