Get(SortOrder)

Returns the sort order as a JSON object.

Format 

Get ( SortOrder )

Parameters 

None

Data type returned 

text

Originated in version 

26.1

Description 

This function returns the sort order of the active window as a JSON object with the following structure:

Copy
{
  "Sort" : 
  {
    "field" : 
    [
      {
        "fieldName" : "Table::Field",
        "overrideLanguage" : "Language",
        "sortOrder" : "Ascending | Descending | Value list name",
        "summary" : "Summary field"
      }
    ],
    "maintain" : "true | false"
  }
}

The following table describes the elements in the returned JSON object.

JSON element Description
Sort

Object that contains the sort order.

field

Array that contains an object for each sort field, in the order specified in the Sort Records dialog.

fieldName

Name of the sort field, including its table occurrence (for example, Products::ProductName).

sortOrder

Sort order of the field. One of the following:

  • Ascending

  • Descending

  • The name of the value list, if specified by Custom order based on value list

overrideLanguage

Language name, if specified for Override field's language for sort, for example Swedish. For the possible names, see Language names for sorting and indexing.

summary

Name of the summary field, if specified for Reorder based on summary field, without a table occurrence.

maintain

Text value, "true" or "false", that indicates whether Keep records in sorted order is selected.

Notes 

  • Each window has its own sort order.

  • The function returns the window's most recent sort order, even if the records are no longer sorted (for example, after you choose Records > Unsort). To check whether the records are currently sorted, use the Get(SortState) function.

Example 1 

If the records are sorted by ProductName in ascending order and Keep records in sorted order is not selected, the function returns:

Copy
{
  "Sort" : 
  {
    "field" : 
    [
      {
        "fieldName" : "Products::ProductName",
        "sortOrder" : "Ascending"
      }
    ],
    "maintain" : "false"
  }
}

Example 2 

Saves the sort order of the active window in the Reports::LastSortOrder field before a script changes the found set. If the records aren't sorted, the field is set to an empty value.

Copy
Set Field [ Reports::LastSortOrder ;
    If ( Get ( SortState ) = 0 ; "" ; Get ( SortOrder ) )
]

Example 3 

In a layout in List View, a Category subsummary part displays a heading when the records are sorted by Category. The Category field in the body part then repeats the heading in every row. To hide the body's Category field in that case, enter this formula as the Hide object when condition (see Hiding or showing layout objects).

Copy
Get ( SortState ) ≠ 0 and
JSONGetElement ( Get ( SortOrder ) ; "Sort.field[0].fieldName" ) = "Products::Category"

The calculation returns 1 (and the field is hidden) only if the records are sorted and Category is the first sort field. Otherwise, it returns 0. The Get(SortState) test is needed because after choosing Records > Unsort, the function still returns the last sort order.