- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-21-2021 08:32 AM
There are several questions in community that might be related to the same functionality, but since neither of them completely repeats my request, I decided to write a separate article, referencing these questions below.
Introduction
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.
Related links
List of all available dictionary attributes (ServiceNow documentation)
Auto-complete for reference fields (ServiceNow documentation)
Sorting in descending order for reference type variables in servicenow portal (Community question)
Sorting list order is not working in List collector (Community question)
How can I get a reference field's pick list to display in a sorted order? (Community question)
- 7,624 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have a question regarding the descending sort order and step 2 (the Before Query Business Rule). If I am trying to use this in a Reference field in a Catalog Item, how do I create this Business Rule to only affect that field in that particular Catalog Item?
Basically, I have a Reference Field returning records from the Number field of the Change Request table, and I only want this Sort order applied to my particular Catalog Item, and not to all forms that reference Change Requests.