Location ref qualifier joining script includes

dave_edgar
Mega Guru

I want to show locations but I want anything where the country contains ireland to display at the top of the list then everything else.

 

I have a script include written to build the array BUT the list is resorting itself when viewed.  Is there a way around this with just having a new field to determine the order?

 

getIrelandLocations: function() {
		
        var locationList = [];

        // Query the location table
        var gr = new GlideRecord('cmn_location');
        gr.addQuery('country', 'CONTAINS', 'reland');
		gr.orderBy('name');
        gr.query();

        // Add sys_ids of records containing 'Ireland' in the name
        while (gr.next()) {
			locationList.push(gr.getUniqueValue());
        }

        var grow = new GlideRecord('cmn_location');
        gr.orderByDESC('name');
        grow.query();

        // Add sys_ids of remaining records
        while (grow.next()) {
			locationList.push(grow.getUniqueValue());
        }

        return locationList;
    },

dave_edgar_0-1696502714378.png

 

 I've even tried to split the arrays but they will not join together, i just get the first list, with an alterted SI of course 
javascript:'sys_idIN' + new LocationsIrelandthenROW().getIrelandLocations() +'^NQ'+ new LocationsIrelandthenROW().getROWlocations();

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

Hi Dave,

Keep the reference qualifier as simple as possible to display the (filtered) list of records.  Use the ref_ac_order_by attribute to name the field that determines the order (ascending).  If you don't have a field that when sorted ascending has the order you desire, you can also create a before Query Business Rule to manipulate the array, just be aware that this will change EVERY reference and list view of the location table.  A workaround to this if you only want this special order one place is to create a Database View self-joining the location table, then apply the Business Rule and this reference field/variable to this view.