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!
Discussion posts and replies are publicly visible
Use to todatasubset() function to sort your data stored in local variables.
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!
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
That's interesting. Peter Lewis, 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 ) ) ) )
Odd, I tried running what you had and got this result:
This is v22.3 if that helps
FWIW i believe Stefan was confirming he got the same behavior you pictured. I also get similar behavior when trying an exact copy of his code (though only after i fix the record type reference for user in the toDataSubset call).
Thanks for tagging me Stefan - this is a bug that we plan to fix soon. For now you can likely achieve the behavior you need by casting to a map, doing the sort there, and then casting back to a list of record types.
I actually seem to have gotten it working using stefan's example above (though what a pain to fix the record type references that don't actually resolve correctly copy/pasting the text...), by replacing the "field" in a!sortInfo with the plaintext value "firstName", instead of the recordType field reference. Is this also incorrect?
edit: also interestingly this works as well:
That's curious, I am also able to recreate your results using the User record. However, when I apply the same concept to my own record, I am unable to recreate it...
Peter, thanks a lot for the update.