ORDERBYDESC on Two columns is not working on Service Portal Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:16 AM - edited 03-10-2023 06:17 AM
I am gliding the most viewed and most rated kb articles in service portal widgets using the query below. But the sorting is not applying properly. Only sorting is applying on single column . Please suggest.
gr.addEncodedQuery('GOTO123TEXTQUERY321='+ data.q+'^ORDERBYDESCrating^ORDERBYDESCsys_view_count');
Thanks,
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:36 AM - edited 03-10-2023 06:37 AM
Hi @Vijay1212 ,
the sorting is not applying as expected because you are using two separate ORDER BY clauses. You can try combining them into a single ORDER BY clause using comma-separated values like this:
gr.addEncodedQuery('GOTO123TEXTQUERY321='+ data.q+'^ORDERBYDESC rating, DESC sys_view_count');
This should sort the results first by rating in descending order, and then by sys_view_count in descending order as well.
Alternatively, if you want to sort by sys_view_count first and then by rating, you can change the order of the columns in the ORDER BY clause like this:
gr.addEncodedQuery('GOTO123TEXTQUERY321='+ data.q+'^ORDERBYDESC sys_view_count, DESC rating');
This will sort the results first by sys_view_count in descending order, and then by rating in descending order as well.
Regards,
Shravan
If my answer solved your issue, please mark my answer as Correct & Helpful
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:53 AM
Hi @Sai Shravan ,
Thanks for your response. I have updated the query as below as you mentioned.
resultGR.addEncodedQuery('GOTO123TEXTQUERY321=' + data.q + '^ORDERBYDESCrating,DESCsys_view_count');
with this query, I am getting the records as below order.
Number | View Count | Rating |
KB0028930 | 7 | 5 |
KB0027001 | 20 | 5 |
KB0027084 | 2 | 5 |
KB0027430 | 0 | 5 |
KB0023716 | 0 | 5 |
KB0030787 | 80 | 5 |
KB0030442 | 0 | 5 |
KB0026826 | 26 | 5 |
KB0026750 | 0 | 5 |
KB0026252 | 176 | 5 |
KB0030230 | 1 | 5 |
KB0010676 | 0 | 5 |
KB0027306 | 0 | 5 |
KB0029371 | 0 | 5 |
KB0029351 | 8 | 5 |
but i am expecting the result should be as below.
Thanks,
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:58 AM
Hi @Vijay1212 ,
To sort the records in descending order by both fields at the same time, try the below code
resultGR.addEncodedQuery('GOTO123TEXTQUERY321=' + data.q + '^ORDERBYDESCrating,ORDERBYDESCsys_view_count');
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:23 AM
Hi @Sai Shravan ,
I have modified the query. but issue isnot solved. I am not getting what exactly the issue is.
I have run the query using background script..but no luck.
Thanks,
Vijay