how to add order by in the existing encoded query

Priyanka Shind1
Kilo Expert

Hello All,

I have used below encoded query and I want to add order by on opened_at field which is a date field.

At present it is showing old to new records however I want to showcase new to old records.

Below is my encoded query copied from incident table

caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^opened_atONLast6months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()^EQ

Thank you in advance.

Regards,

Priyanka Shinde

1 ACCEPTED SOLUTION

Shakeel Shaik
Giga Sage
Giga Sage

Hi Priyanka

ORDERBYDESC = New to Old

caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^opened_atONLast6months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()^EQ^ORDERBYDESCopened_at

Thanks,
Shakeel Shaik 🙂

View solution in original post

6 REPLIES 6

Maik Skoddow
Tera Patron
Tera Patron

Hi @Priyanka Shinde 

please see page https://docs.servicenow.com/bundle/sandiego-platform-user-interface/page/use/using-lists/concept/c_E...

You will find there the explanation for adding the sort order to an encoded query string.

 

Kind regards
Maik

Hello Maik,

Thank you for your reply.

 

Will you be able to help me add the mentioned sorting condition available in the doc to my existing encoded query. I want to sort on opened date.

caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^opened_atONLast6months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()^EQ

caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^opened_atONLast6months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()^EQ^ORDERBYopened_at

Voona Rohila
Kilo Patron
Kilo Patron

Hi Priyanka

you can use orderBy/orderByDesc.

grIncident.orderByDesc('opened_at'); - for descending order and

grIncident.orderBy('opened_at'); - for ascending order.

 

sample:

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("active=true");
grIncident.orderByDesc('opened_at');//descending order.
grIncident.query();
while (grIncident.next()) {
 //
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP