9 Replies Latest reply on Mar 5, 2015 12:26 PM by SimonOuellet

    How to sort portal records with a script?

    SimonOuellet

      Title

      How to sort portal records with a script?

      Post

      I want to have multiple ways to sort the related records of a portal (using different scripts). What is the script function that would let me do that? I know how to sort using script, but not through a portal...

      I know it's probably a simple (stupid) question, but i can't figure it out.

      Thanks

        • 1. Re: How to sort portal records with a script?
          philmodjunk

          That's because it's not simple. Portals cannot be dynamically sorted. We end up having to simulate dynamic sorting. 

          Method 1. Create multiple copies of the same portal, but specify a different sort order in portal set up for each copy. Then put each copy into a different panel of a slide or tab control. You then "sort" your portal by selecting a different panel of your control. A script can use go to object to bring a panel to the front. 

          Method 2: a case function canbe set up in a calculation field to refer to a global field or variable to return the value of different portal fields. You sort your portal on this field and change the value of the field/variable to change the sort order. The calculation field returns a text type and formats numbers with leading zeroes. 

          • 2. Re: How to sort portal records with a script?
            SimonOuellet

            Thanks, i was under the impression it was easy...

            I tried the first method (simpler) but i don't like how it looks. I don't want different tabs around my portal.

            I understand the idea of your second method (the portal is sorted with a field that changes with a script). I'm just not sure exactly how to do this. I've never used case function before. I looked in the help and i think i understand how it works. How can i use this to change the number of the the sorting field? What calculation would take a global field in consideration to reverse the order of the sorting field based on what i put in that global field?

             

            • 3. Re: How to sort portal records with a script?
              philmodjunk

              A tab or slide control can be invisible, if you select "no" fill or border color. I'd use a slide control to avoid dealing with tab labels. 

              • 4. Re: How to sort portal records with a script?
                philmodjunk

                A tab or slide control can be invisible, if you select "no" fill or border color. I'd use a slide control to avoid dealing with tab labels. 

                The other method is not one that I often use. Found it in one of the Filemaker training series books a few versions ago so I don't recall if there was a way to reverse the order. 

                The case function would look like this:

                Case ( GlobalField = field 1; Text field ;

                             GlobalField = field 2; right ( "00000" & IntegerField, 6);

                             )

                • 5. Re: How to sort portal records with a script?
                  SimonOuellet

                  Even if the tab is "no fill" and the name of the tab is empty, the user can still click on the tab (even if he doesn't see it) and change the tab shown. Can i make the tab not clickable? The only way to change the tab would be through a script.

                  • 6. Re: How to sort portal records with a script?
                    philmodjunk

                    If the tab label is 0 pixels wide, it can't be clicked. And I suggested a Slide Control as that avoids the issue altogether. (With a Slide control, you can choose to not have the "dots" that control what panel is visible.)

                    • 7. Re: How to sort portal records with a script?
                      SimonOuellet

                      I have FMP 11, so i don't have slide control. Nonetheless, it now works with a tab.

                      Thanks a lot for your help!

                      oui

                      • 8. Re: How to sort portal records with a script?
                        philmodjunk

                        In the future, please tell folks you are using an older version if you post a question to a forum like this. It didn't make much difference this time, but when you don't tell people, there's a chance that someone will take a good deal of time to suggest an answer only to discover that it won't work because you aren't using the latest version of FileMaker.

                        • 9. Re: How to sort portal records with a script?
                          SimonOuellet

                          You're right, i'm sorry....Thing is, i really thought it was easy so i didn't bother telling the fmp version i'm using. In the future i will.

                          I did an "invisible" portal with 0 pixel for tabs and it works perfectly.

                          Thanks again.