Sorting list from a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2023 06:54 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2023 10:05 PM
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.
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2023 01:18 AM
Thanks for that @BharathChintala. How do I use it though?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2023 01:52 AM
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.
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.
- Add the "ref_ac_order_by=<field_name>" to the reference field.
- 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.
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.
.
Bharath Chintala