Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to sort strings that contain dates in a reference variable?

Smith Johnson
Kilo Sage

Hello,

I have a variable "Period" in a catalog item which is a reference variable, and displays the following values.

SmithJohnson_1-1752048894181.png

 

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.

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Smith Johnson 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.

@Smith Johnson 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader