- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2016 02:17 AM
I have a table X, in that i have three fields as a,b,c.
if i reference this table i have set 'a' field as display to true.
if i give the table name i want to get field name of which i was set display to true.
can any one help me in this issue.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2016 03:34 AM
Try this code. It does a complete search. It worked on all the tables I tested.
function getDisplayField(table) {
var i, currentTable, deo, dict;
var hierarchy = String(new TableUtils(table).getHierarchy());
hierarchy = hierarchy.substring(1,hierarchy.length-1).split(', '); // turn List into Array
for (i = 0; i < hierarchy.length; i++) {
currentTable = hierarchy[i];
// Check for Dictionary Entry Overrides first
deo = new GlideRecord('sys_dictionary_override');
deo.addQuery('name', currentTable);
deo.addQuery('display_override', true);
deo.query();
if (deo.next())
return String(deo.element);
// Check the Dictionary next
dict = new GlideRecord('sys_dictionary');
dict.addQuery('name', currentTable);
dict.addQuery('display', true);
dict.query();
if (dict.next())
return String(dict.element);
}
// No display values have been defined. Look for a default field
var defaults = ['number','u_number','name','u_name'];
for (i = 0; i < defaults.length; i++) {
dict = new GlideRecord('sys_dictionary');
dict.addQuery('name', 'IN', hierarchy);
dict.addQuery('element', defaults[i]);
dict.query();
if (dict.next())
return String(defaults[i]);
}
// No display value
return 'sys_id';
}
var displayField = getDisplayField('sys_user');
gs.log('displayField: ' + displayField);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 11:27 PM
You can use getDisplayName() method available on GlideRecord
var gr = new GlideRecord("table_name");
gs.log(gr.getDisplayName());
This retrieves the name of the display column from the table.