3 Replies Latest reply on Dec 22, 2010 2:23 PM by philmodjunk

    Cycling through records through a Single Row Portal Using a button

    DanielKwon

      Title

      Cycling through records through a Single Row Portal Using a button

      Post

      I have two Tables. A parent called Allotment and a child called Stock. The stock table has 4 fields I want to display.  Using the Allotment layout, I am trying to create a portal that has a single row. I want to create a button that will cycle between different child field values from the child table.

      Thank you for any guidance / help. 

        • 1. Re: Cycling through records through a Single Row Portal Using a button
          philmodjunk

          Are you using FileMaker 11? If so a portal filter can be set up for this. If not, a similar method with a filtered relationship can be used.

          Use a script trigger with OnRecordLoad to perform this script when a given record is first brought up on your layout:

          Freeze Window
          If [IsEmpty (PortalTable::PortalID ) /* check for related portal records */]
             Set Variable [$$ID ; 0 ]
          Else
              Go To Related Record (//specify a layout based on your portal table and show only related values, current record here)
              Go TO Record [first]
              Set Variable [$$ID ; PortalTable::PortalID]
              Go To Layout [original layout]
              Refresh Window [flush cached join results]
          End If

          You'll use the layout specified in the GTRR step to keep track of which record is currently displayed in your portal.

          Your "next" button's script would look like this:

          Freeze Window
          Go To Layout [//specify same layout as specified in GTRR above]
          If [Get ( FoundCount ) >  Get ( RecordNumber ) and $$ID > 0 ]
              Go To Record [next]
              Set Variable [$$ID ; PortalTable::PortalID]
              Go To Layout [original layout]
              Refresh Window [flush cached join results]
          End IF

          The "previous" script will be very similar, but uses Get ( RecordNumber ) > 1 and $$ID > 0 in the IF statement and Go To Record ( Previous ) further down in the script.

          Your portal filter expression would be: $$ID = PortalTable::ID

          Note: PortalTable::ID must be a field--typically an auto-entered serial number field--that uniquely identifies the portal record. (Record ID's could also be used in this method.)

          • 2. Re: Cycling through records through a Single Row Portal Using a button
            DanielKwon

            Thank for the help. I've tried applying the solution you've posted. However, I'm currently running an issue where the script runs indefinitely. I put a beep in the script, and it goes non stop. Let me be more specific about my Table structure and implementation. 

            I have a Stock table. Primary keys are Lot(FK,PK) and Part Number(PK). The other fields are Location, Zip Code, and Quantity. I have a second table Allotment. It has only field Lot (PK). I have a layout for Stock which simply displays all fields from the table. My Allotment table displays the Lot from the Allotment table and related values from Stock except lot. I'm currently using a single row in my portal to display the information. 

            • 3. Re: Cycling through records through a Single Row Portal Using a button
              philmodjunk

              This is a situation where if you have FileMaker Advanced, you can enable the script debugger and then watch the script or scripts execute one step at a time.

              If you don't have advanced, insert a Show Custom Dialog step at the beginning of your script. Click your button and see if the dialog ever appears. If it doesn't, some other script is being perfomed via a scirpt trigger and it's trapping you in some kind of infinite loop. If it does, keep adding more Custom Dialogs as needed to isolate where it's going off the rails. If it happens at a point where the script changes layouts or changes to a different record, check Layout Setup... | Script Triggers to see if some other script is being performed at this point.

              I suspect a script trigger here, because the scripts I've recommended don't have any loops in them.