Improve Display of Values for a List Reference Field in the form

gtfoster
Tera Contributor

I am trying to get the list of values for a reference field to display in alphabetical order and for each value to display on a new line. Attached is how it currently looks, below is how I would like it to look:

Supporting Analyst

Abel Tuter,

Tamara Declue,

User 1,

Zane Sulikowski

1 ACCEPTED SOLUTION

There are not any settings or configuration change options for list fields, but you could run a script like this to re-order the values - I haven't found anything to put each one on a separate line:

var arr=[];
var  lst = new GlideRecord('sys_user');
lst.addQuery('sys_id', 'IN', current.u_list); //list field name
lst.orderBy('name');
lst.query();
while (lst.next()) {
    arr.push(lst.sys_id.toString());
}
current.u_list = arr.join(',');

This would be in a Business Rule before insert and update on the incident table when the list field changes.

You could also run this as a Fix Script to modify all of the existing records - excluding or using a different addQuery, and changing the last line to a setValue and adding a lst.update();

If you really need to see it on the form each time a user is added or removed, you could put something like this in a Script Include and call it with a GlideAjax onChange of the field.

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Is it possible for this field to be populated when the form/record is loaded, so you want to see this then, and/or could the Supporting Analyst field be changed while the record is displayed, so the solution would have to work onChange of this field?  Where are you viewing these records - native UI, Service Portal, workspace,...?

Currently it is in the form of an incident. I am recreating something in my PDI at a very basic level for another project. Screenshot included.

There are not any settings or configuration change options for list fields, but you could run a script like this to re-order the values - I haven't found anything to put each one on a separate line:

var arr=[];
var  lst = new GlideRecord('sys_user');
lst.addQuery('sys_id', 'IN', current.u_list); //list field name
lst.orderBy('name');
lst.query();
while (lst.next()) {
    arr.push(lst.sys_id.toString());
}
current.u_list = arr.join(',');

This would be in a Business Rule before insert and update on the incident table when the list field changes.

You could also run this as a Fix Script to modify all of the existing records - excluding or using a different addQuery, and changing the last line to a setValue and adding a lst.update();

If you really need to see it on the form each time a user is added or removed, you could put something like this in a Script Include and call it with a GlideAjax onChange of the field.

gtfoster
Tera Contributor

***Accidental reply***