3 Replies Latest reply on Jul 22, 2014 7:23 AM by philmodjunk

    Sorting records based on a variable field to be specified

    wladdy

      Title

      Sorting records based on a variable field to be specified

      Post

           I need a script to perform a sort on a field which will vary depending on the active layout. For instance, if the layout is called "A", the sort field would be "Clients::Names", whereas if the layout is called "B", the sort field would be "Suppliers::Country".
            
           Right now, I can only think of using an If-Else construction, but surely there must be a better way...
            
           I can easily define in a variable (or in a global field) the name of the sort field. Could somehow use this variable to perform the sort...
            
           Many thanks! W. 

        • 1. Re: Sorting records based on a variable field to be specified
          RickWhitelaw

               Use a sort script step triggered by OnLayoutEnter.

          • 2. Re: Sorting records based on a variable field to be specified
            wladdy

                 Thank you for your reply.

                 Unfortunately, this would not solve my problem as I need my script to be triggered by the push of button, and not upon entering the layout. Furthermore, the OnLayoutEnter trigger is already used in most of the layouts where I want to use the script.

                 My question is more about the possibility to execute a 'Sort Records' script step (or a 'Perform find' script step, for that matter) targeting a field whose name would be the result of a calculation, a little bit like the 'Set Field By Name' script step target a field.

            • 3. Re: Sorting records based on a variable field to be specified
              philmodjunk

                   If each field on which you want to sort is present on the layout, you can:

                   Give each field object for a field on which you want to sort, give it an object name using the Inspector's Name box.

                   Then this script might be used:

                   Go to Object [ Get ( ScriptParameter ) ]
                   Sort Records by Field [ascending]

                   Sort Records sorts records by a single specified field. If you do not specify a field in the script, this step uses whatever field is currently the active field so go to object can be used to put the focus into a specific field. You'd pass the object name to the script as a script parameter specified in either button set up or in the script trigger setup where this script is specified as the script to run when that button is clicked or that trigger is tripped.