How to sort GlideRecord results by Date and Alphabetical to pass to ng-repeat in portal widget?

patricklatella
Mega Sage

Hi all,

we have a custom widget in our portal that is showing the results of a GlideRecord query.  The results are presented via an ng-repeat in the HTML to show columns and rows of the returned records.  I'm looking for how to pass the results to the widget's HTML so they are sorted first by a date field on the table, and then alphabetically by a "Requested for" field.

 

I see how to sort by date and also how to sort by alphabetically using orderBy();, but how do I achieve the sort by both?

 

So results would be something like this...sorted first by Date, and then within a date sorted by "Requested for" first name:

 

Date                                      Requested for

4/5/2022                             Joe Employee

4/5/2022                             Rick Otherguy

4/5/2022                             Sue Accountant

4/6/2022                             Anne Lawyer

4/6/2022                             Fred Judge

 

 

any help would be great...thanks!

1 ACCEPTED SOLUTION

patricklatella
Mega Sage

This turned out to be easier than expected...just needed to add the orderby() for the date field and for the name field, and then when pushing the data to the array the date needed to be included as the display value.  Dates sorted, and then within each date the results are sorted alphabetically.  See screenshot for script.

View solution in original post

2 REPLIES 2

patricklatella
Mega Sage

Here's a screenshot of my GlideRecord.  You can see on line 26 I'm pushing the results to the HTML...this is where I need the results sorted according to my requirement.

patricklatella
Mega Sage

This turned out to be easier than expected...just needed to add the orderby() for the date field and for the name field, and then when pushing the data to the array the date needed to be included as the display value.  Dates sorted, and then within each date the results are sorted alphabetically.  See screenshot for script.