4 Replies Latest reply on May 22, 2009 3:34 AM by KIDO

    Portal problem (sorting records)



      Portal problem (sorting records)


      The problem I am facing is that I have created a portal with different types of fields and I want to be able to sort those records.


      The fields are called Docu. Name,Docu. Group,Docu. Type, Docu. Date


      Now I am able to always sort them according to their date as i chose in (Portal Setup, specify sort and than chose the field docu. date),

      but what i actually want is that i can press on the field e.g docu date and than it sorts all my documents according to the date they were created.


      If i press on docu. type it should sort them according to their type....or if i need to see what group these documents are in,I can press on the field docu. group and it sorts them according to the group they are in......


      while what I have now it will always be sorted by date.



      How is that possible?I've tried it through setting up each field by (button setup,sort records)....but it somehow does not sort them once I've done all that and than click on either of the fields it never sorts them accordingly. Maybe its because it is a portal but I'm not sure about that...however this is the only reason I can think of why it isn't working.



      I hope anyone understands what I'm trying to do

        • 1. Re: Portal problem (sorting records)
             See if this helps.
          • 2. Re: Portal problem (sorting records)
               how do i add a snapshot of what i have onto this forum? so i could show what i have right now....which makes everything easier to understand 


            • 3. Re: Portal problem (sorting records)



              Thank you for your post.


              You cannot add a snapshot to the forum.  Instead, put the snapshot on a server, and then put a link to it on the forum.



              FileMaker, Inc. 

              • 4. Re: Portal problem (sorting records)

                Hi Mike


                Try the following


                <!--            @page { margin: 2cm }           P { margin-bottom: 0.21cm }        -->

                Building up our Portal Sort.

                To build our portal sort we need 2 global text fields to store the sort flag and the name of the field being sorted. These can be added to the portal table, or included in a global table so they become available across the application. We also need a numeric field with an auto-enter calculation in our portal table, a custom function to convert text and a script to execute and control the sort.

                Create 2 text global fields (Globals::sort_flag and Globals::sort_field in the example below). Globals::sort_flag will store “A” for ascending or “D” for descending, depending on selected direction, whilst Globals::sort_field will store the name of the field being sorted.

                Create a field type number in your portal table, YourTableName::z_sortfield in this example. In Auto-Enter select Calculated value and insert the calculation:

                Let ( [ MYSORT = TableName::z_sortfield ];

                Case ( Globals::sort_flag = "D"; -MYSORT; MYSORT ) )

                This will convert the field contents to negative numbers when descending is selected.

                Select MENU / FILE / MENAGE / DATABASE..., select the RELASHIONSHIP tab and in the relationship graph set a relation between your tables. Double click in the relationship and in the relationship window, on your portal table side, select Sort records / specify and select your sort field TableName::z_sortfield. Define the sort as Ascending. Click OK until you leave the database management.

                Alternatively, you can define your sort in the layout selecting your portal and in MENU / FORMAT / PORTAL SETUP... specify your sort “Ascending”.

                Create a Custom function: MENU / FILE / MANAGE /CUSTOM FUNCTIONS... NEW

                Function name : TextToNum

                Parameters: text /* Text to be converted */

                value /* Numeric value returned */

                under TextToNum ( text; value ) =

                insert the following calculation:

                Let( [ LEN = Length(text) ];

                Case(LEN > 0;

                TextToNum( Right ( text ; LEN - 1 ); Upper( Right(Left ( text ; 1);1) & value ));

                "." & GetAsNumber ( Substitute ( GetAsText(Code (value)); "000"; "" )) ))

                Click OK until leave the custom function.

                Now, write your script – Sort Portal -

                # Define initial sort order: empty Globals::sort_flag or sorting on different field.

                If [ IsEmpty ( Globals::sort_flag ) or Globals::sort_field Get (ScriptParameter) ]

                Set Field [ Globals::sort_flag ; ”A” ]

                End If

                # Save the parameter (sorting field name) to control initial order of sort on other fields

                Set Field [ Globals::sort_field ; Get (ScriptParameter) ]

                # Determine the sort field type and use appropriate calculation

                IF [ MiddleWords (FieldType (“YourDatabaseName” ; Get (ScriptParameter)); 2; 1) = “Text” ]

                Replace Field Contents [No dialogue; YourTableName::z_sortfield; TextToNum ( Evaluate ( Globals::sort_field ); "" ) ]

                Else # the field must be converted to number

                Replace Field Contents [No dialogue; YourTableName::z_sortfield; GetAsNumber( Evaluate ( Globals::sort_field )) ]

                End If

                # Toggle sort direction flag

                If [ Globals::sort_flag = “A” ]

                Set Field [Globals::sort_flag ; “D” ]


                Set Field [Globals::sort_flag ; “A” ]

                End If

                Now is time to create buttons or use the column headlines as buttons and set them up to perform the script “Sort Portal” with the respective fieldName as a script parameter.