How to sort strings that contain dates in a reference variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 01:21 AM
Hello,
I have a variable "Period" in a catalog item which is a reference variable, and displays the following values.
However, considering that these values contain dates, I would like them to be sorted based on their start date in an ascending order. So it should look like this: 10/07/2025 - 24/07/2025, 31/07/2025 - 07/08/2025, 08/09/2025 - 10/09/2025.
Even if I have an advanced ref qualifier calling a script include which sorts the values based on the start date, in the catalog item it is still sorted alphabetically (refer to the img above).
How can I disable the alphabetical sorting? Or any other ideas?
Thank you,
Smith.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 01:55 AM
you can add variable attributes for this provided the date you are seeing in above screenshot is picked from a date or date/time field
But it seems it's a choice field on that referenced table
what's your use-case?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 02:32 AM
Hello, thank your for your reply. The use case is the following:
- The period variable in the catalog item, makes a reference to the "cmn_schedule" table. So, the values that are found in the drop-down, are actually the names of the schedules.
- However, the start and end date are stored in the associated schedule entry ("cmn_schedule_span" table).
So, I have a script include that is able to sort the schedules (based on the start date of their associated schedule entries). The thing is that even if the script include returns something like this: return "sys_idIN<sys_id1>,<sys_id2>,<sys_id3>", the order is not respected in the ref qualifier. It still displays them in alphabetical order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 02:54 AM
I don't think it will sort like that.
It might not be supported.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
