Sorting list from a table

Red
Giga Expert

I have built a table and I am using the values from this table for a lookup select box for a record producer/form. I need to be able to sort the values by the order in which I have entered them, and another time to sort them alphabetically. How can I do this one? 

3 REPLIES 3

BharathChintala
Mega Sage

@Red 

Can you have this isOrder attribute on any of the field on that table.

Also we can sort this list as per requirement by using before query Business rule. And also user preference is important in sorting.

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Thanks for that @BharathChintala. How do I use it though? 

 

There is autocomplete in Reference fields to provide a user more convenient way to select the relevant record from the list, without additional clicks on the magnifying glass. However, some functionality that seems trivial is either not available, or can be reached only through a workaround.

 

Sort in descending order

There is the attribute in Reference fields called "ref_ac_order_by". It works great, but the default sorting order is ascending (a-z) and there is no option to change it. If one sorts by a String field, the sorting order a-z perfectly makes sense. But if the sorting should go by a date or a record number, it is usually would make more sense to see the newer on top, and currently it's not.

BharathChintala_0-1673862698659.png

 


Is there a way to sort the list in descending order?

Answer: yes, there is. Combination of "ref_ac_order_by" dictionary attribute and before query business rule is required.

  1. Add the "ref_ac_order_by=<field_name>" to the reference field.
  2. Create the before query business rule as below:
    (function executeRule(current, previous /*null when async*/) {
       current.orderByDesc('<field_name>');
    })(current, previous);

NOTE: According to my check, it works only in the combination, at least in my specific case. 

 

Increase the number of displayed rows

The default in the autocomplete list is 15 records.

BharathChintala_1-1673862698671.png

 


There is a system property to control it. However, what if there is no need to change the default in the whole instance but only for a specific field. Is it possible?

Answer: no, it's not. The official answer of the ServiceNow support:
"There is no other way to limit it. It can be only be done for a sys_property affecting the complete instance.
It cannot be field specific."


NOTE: Both questions are NOT RELATED to the pop-up list that appears once the "Lookup using list" (magnifying glass) is clicked, only to the autocomplete list that appears once user starts typing something in the reference field.

.

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala