2 Replies Latest reply on Apr 16, 2017 1:41 PM by philmodjunk

    Auto increment in portal

    milky

      Hi everyone,

      Hope you all had a good Easter.

      I have created a DB for a poker tournament where players receive a varying amount of chips for a “grand final” event.

      To make it fair for all players, we need to distribute the large stacks and the small stacks evenly.

      I populated a portal that shows:

      Players::PlayersName, Players::ChipTotal, Players::TableNumber and Players::SeatNumber.

      The portal is sorted by Players::ChipTotal, highest to lowest and then Players::TableNumber lowest to highest.

      I have a field - Event::TablesRequired, that the user can specify how many tables will be required for the grand final.

      Each table will hold 10 players, so let's assume there will be 180 players, the user would enter 18 into the field Event::TablesRequired     

      (total players / 10)

      What I need assistance with is how to write a script to:

      Go to the first portal row.      Set field Players::TableNumber to 1

      Go to next portal row.            Set field Players::TableNumber to 2

      And continue until this sequence is completed the specified x number of times that was entered in the field Event::TablesRequired.

      The script then needs to go to the next portal row where the Players::TableNumber is blank (in this example, 19) and continue the same sequence as above and again and again until all portal rows have table numbers filled. Basically 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 looped Ten times.

      Once the script has ended the original portal sort would cause players on the same table number to be grouped together.

      I would then need another script that would insert the following sequence of numbers into the Players::SeatNumber     10,3,8,4,1,9,6,2,5,7.       18 times – or x number of times that was entered in the field Event::TablesRequired.

       

      I am using FMP12 Adv with Windows 10.

       

      Any help at all would be greatly appreciated.

      Milton.

        • 1. Re: Auto increment in portal
          Jaymo

          Here's a basic portal loop which should get you started on your way:

           

          Go to Object [Object Name: "MyPortal"]

          Go to Portal Row [First]

          Loop

            Set Field [MYTABLE::TableNumber; $Counter + 1]

            Go to Portal Row [Next; Exit after last]

          End Loop

           

          This script assumes the option to add related records is turned off on the relationship. If this makes sense to you, let us know more about what you want to do instead of how you want to do it. I was little confused so I wanted to post something to get you started. Screen shots are welcome.

           

          BTW, you need to name your portal with the Inspector so the the Go to Object script step can tell the Go to Portal Row script step the correct portal.

          • 2. Re: Auto increment in portal
            philmodjunk

            I would never do this by looping thru portal rows.

             

            Better to either pull up a found set of these records on a layout based on the portal's table and loop thru those records or pull up a list of the portal records' primary keys and loop thru the list using a relationship to access the correct related record.

             

            This avoids layout based issures that can arise from trying to loop thru portal rows.