Skip to main content
Known Participant
February 16, 2023
Question

Sorting Record Dataset

  • February 16, 2023
  • 10 replies
  • 0 views

Is there a way to sort a record dataset after it's been queried? I have a list of records I got from a queryRecordType stored in a local variable that I am using in multiple places on an interface. I only want the record dataset to be sorted in a particular way for only one instance on the interface, but I want to leave it alone in all other instances, so I don't want to sort the data set within the initial queryRecordType call in the local variable. The only solution I've thought of is query the record again but this time sort it the way I want and store it in a new local variable or write my own expression rule to be able to sort records. I am not allowed to install plug-ins on my environment by the way.

Thanks!

10 replies

stefanhelzle0001
Brainy
February 16, 2023

Use to todatasubset() function to sort your data stored in local variables.

Known Participant
February 16, 2023

I've tried it this way and it is not working:

local!test is a list of records, and I tried to sort on the field "value" as seen above which did not sort the records. I also tried sorting on the field but I called it as a record (recordtype!record.field.value) and it gave me an error:

Not too sure if I did it correctly or not, so any help would be appreciated!

stefanhelzle0001
Brainy
February 17, 2023

That's interesting. [mention:6b9f80ff18f9420082d13ef2d5121d56:e9ed411860ed4f2ba0265705b8793d05], is that the expected behaviour? I could easily replicate this using the built in user record.

a!localVariables(
  local!records: {
    'recordType!{SYSTEM_RECORD_TYPE_USER}User'('recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_firstName}firstName': "Hans"),
    'recordType!{SYSTEM_RECORD_TYPE_USER}User'('recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_firstName}firstName': "Otto"),
    'recordType!{SYSTEM_RECORD_TYPE_USER}User'('recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_firstName}firstName': "Jack"),
    'recordType!{SYSTEM_RECORD_TYPE_USER}User'('recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_firstName}firstName': "Hermine"),
    'recordType!{SYSTEM_RECORD_TYPE_USER}User'('recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_firstName}firstName': "Susi"),
  },
  todatasubset(
    local!records,
    a!pagingInfo(
      startIndex: 1,
      batchSize: -1,
      sort: a!sortInfo(
        field: 'recordType!{SYSTEM_RECORD_TYPE_USER}User.fields.{SYSTEM_RECORD_TYPE_USER_FIELD_firstName}firstName',
        ascending: true
      )
    )
  )
)

harshitb6843
February 17, 2023

See, querying a record is not as expensive as querying a table assuming you have sync enabled. So the first and most convenient option is query record again. 

If you somehow really don't want to do that, then you will have to create a map (dictionary) first from your record data and then use the dictionary field as something that can be passed in the sortInfo of the paging configurations