12 Replies Latest reply on Mar 12, 2016 3:01 PM by BruceRobertson

    Auto resequence list

    laguna92651

      What should be the approach if I had a batting order list on a portal. The portal is sorted on Batting Order. I would like to be able to enter a new order number for a given player, and have the batting order renumber itself and resort.

       

        Batting

         Order  Name

           1      Mike

           2      Joe

           3      Sam

           4      Pete

           5      Mary

           6      Dennis

           7      Randy

           8      Lauren

           9      Al

      If a 2 were entered for the 8 for Lauren, the sequence would update and Lauren would be shown in the number 2 spot and push all of the other players down.

        • 1. Re: Auto resequence list
          Stephen Huston

          Because the portal is sorted on this number, I would run a script trigger on modify for the order number to do several things:

          • Set the order number field to itself –0.5 (forcing it into the correct portal row position, above the row record previously having that number)
          • Commit and refresh the portal, putting the rows in order
          • loop to "walk the portal rows", setting the order# field in each row to its row number, or via a counter $variable,
          • Commit the record
          • 2. Re: Auto resequence list
            user19752

            Using on save trigger may be better.

            • 3. Re: Auto resequence list
              Extensitech

              Stephen Huston wrote:

               

              • Set the order number field to itself –0.5 (forcing it into the correct portal row position, above the row record previously having that number)

              Generally "like he said", and I've used this method myself. For bonus points, though, if they are setting the sequence to a number greater than the original (current) portal row number, add 0.5 rather than subtracting it. Otherwise, if you set 4 to 5, 4.5 wouldn't move (it would still end up on row 4) , and if you set four to 6, 4.5 would end up on row 5.

               

              Chris Cain

              Extensitech

              • 4. Re: Auto resequence list
                beverly

                what works well for me is to ignore the actual NUMBER in the display and use the

                {{RecordNumber}}

                to show the "order". But swapping portal rows is not difficult and using a serial number (that can be changed by swapping) as a sort value will show the portals correctly as you move them around.

                 

                If you need the value of the # (as displayed), then use if the portal row has focus:

                Get(ActivePortalRowNumber)

                https://www.filemaker.com/help/14/fmp/en/html/func_ref1.32.72.html#1065639

                 

                beverly

                • 5. Re: Auto resequence list
                  laguna92651

                  This is the script I am using. With the Commit Records/Request outside the loop, the script creates new records, if I place it inside the loop the Go to Portal Row step is always on row 1.

                   

                  Set Field [ Child::Rank; Child::Rank - .5 ]
                  Commit Records/Requests
                  Go to Object [ Object Name: "TargetPortal" ]
                  Go to Portal Row[ Select; First ]
                  Set Field [ Child::Rank; Get(ActivePortalRowNumber) ]
                  Loop
                  Go to Portal Row
                  [ Select; Next; Exit after last ]
                  Set Field [ Child::Rank; Get(ActivePortalRowNumber) ]
                  End Loop
                  Commit Records/Requests
                  
                  • 6. Re: Auto resequence list
                    BruceRobertson

                    I would do it something like this. Use a global selector field rather than walking the portal.

                    • 7. Re: Auto resequence list
                      laguna92651

                      Thanks Bruce, that looks great, I like the ability to add to the batting order from the roster.

                      • 8. Re: Auto resequence list
                        BruceRobertson

                        Hope you also noticed the onObjectSave script trigger for the order field in the top portal.

                        • 9. Re: Auto resequence list
                          laguna92651

                          Yes I did, thanks for the followup. Why use OnobjectSave instead of OnObjectModify or vice versa?

                          • 10. Re: Auto resequence list
                            BruceRobertson

                            Try both and observe.

                            • 11. Re: Auto resequence list
                              laguna92651

                              Yes I see, I would only be able to enter a single digit number.

                              In working through the script I noticed the script only works if the sort is on the relationship link not the portal sort, why is that?

                               

                              If I make an entry that is later in the batting order, change from 2 to 7, I end up in the number 6 position, because the math is a -0.2. I've been trying to test for whether the new value is less than or greater than the original value, but since the script is run OnOjectSave i can't get the original position value, is there a straightforward way to get the correct new batting order value if the change in batting order position is from 2 to 7?

                              • 12. Re: Auto resequence list
                                BruceRobertson

                                "In working through the script I noticed the script only works if the sort is on the relationship link not the portal sort, why is that?"

                                Yes, that is a good observation and a correct observation.

                                The script uses the List() function to get the related values, in order, That's what the list function does when pointed at a relationship. The list function doesn't care what you've done to the portal sort order, and also does not care what you may have introduced in the way of portal filtering. A list of related values is a list of related values; in the order defined by the relationship.