how to change list order

Shir Sharvit
Tera Contributor

Hi,

The existing code retrieves a list of positions for the caller, including a default position named "other" that is universally assigned to all users. Presently, the "other" position is listed first, followed by the caller's positions. I am seeking assistance to reverse this order, ensuring that the caller's positions are displayed first, with "other" positioned at the end of the list.

 

The sysID referenced in line 18 corresponds to the value "other" from the u_position table.

ShirSharvit_0-1703577524221.png

 

 

this is what the script returns:

ShirSharvit_1-1703577524781.jpeg

 

 

8 REPLIES 8

of course,
 
var PositionForRecordProducer = Class.create();
PositionForRecordProducer.prototype = {
    initialize: function() {},

    refinePosition: function(caller_id) {
        var positionsString = "";

        if (!gs.nil(caller_id)) {
            // Use GlideRecord on the u_m2m_user_positions table
            var userPositions = new GlideRecord('u_m2m_user_positions');
            userPositions.addQuery('sys_user', caller_id);
            userPositions.query();


            while (userPositions.next()) {
                positionsString += userPositions.u_positions + ",";

            }
        //sysID of the value "Other"
            positionsString += "565b2c388793b91088c463573cbb3567,";


        }
        return "sys_idIN" + positionsString;
    },

    type: 'PositionForRecordProducer'
};

@Shir Sharvit Please refer to the knowledge article https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0725720 to set the sort order for the reference field.

 

Hope this helps.

 

 

Ok, what should I write in attributes so that the value "other" is the last in the list?

Try using the name field for sorting.