My approval widget sorting

VJ4
Giga Expert

I have had to make some modifications to the approvals widget so instead of showing only the unapproved tickets, I'm having to show the closed ones as well.

What I need to implement is, for instance, if I limit the pool to 10 and if a user has 3 unapproved tickets it will show those at the top followed by the 7 most recent approved tickets. I managed to get the list to sort by the date a ticket was opened by adding gr.orderBy('sys_created_on'); but I want to also filter for 'active' tickets so if a user has any unapproved tickets they will display at the top? I was wondering if this is doable and if someone could shed some light?

var gr = new GlideRecord('sysapproval_approver');

  1. gr.setLimit(10);
  2. gr.orderBy('sys_created_on');

Thanks in advance.

1 ACCEPTED SOLUTION

Oh!


I see.


You can use the
gr.orderByDesc() multiple times and that way set more than one column to sort by



gr.orderByDesc('column_A')


gr.orderByDesc('column_B')


gr.orderByDesc('column_C')






Guessing that solves you problem right ?


View solution in original post

9 REPLIES 9

Stewe Lundin
Mega Guru
  1. var gr = new GlideRecord('sysapproval_approver');  

gr.addQuery('active',true)


gr.orderByDesc('sys_created_on');


gr.setLimit(10);


gr.query();


Thanks Steve, but this will only show the active ones? I want to show both and if a user has any active ones they will show first followed by the approved ones.


Oh!


I see.


You can use the
gr.orderByDesc() multiple times and that way set more than one column to sort by



gr.orderByDesc('column_A')


gr.orderByDesc('column_B')


gr.orderByDesc('column_C')






Guessing that solves you problem right ?


Otherwise you will have to sort through them in code and then present them "out of order" from the data set.
Perhaps create a Ditionary with al the glideRecords in and usse that to present the data.



Think that is going to be messy.