"Table Name" and "Field Name" types does not have a Display Value?

danielnagy
Giga Contributor

You know there are certain field types on a table, and two of the less known are "Table Name" and "Field Name". You can make the Field Name dependent on the Table Name and there you have a nice way to pull tables and their fields, and do some tricks with them. They are supposed to be some kind of reference fields. And as we know Reference fields usually have a Name (e.g: sys_created_on) and a Label (e.g.: Created).

The problem is that it looks impossible for me to pull the Lables with getDisplayValue() on these two field types. Also tried getValue() without success.

So I tried to find out whats going on.

When I create a dummy test table and create one "Table Name" and one "Field Name" field on it (bold tags), and then I click "Show XML" I see:

<xml>
<u_totestfieldnametype>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2018-09-04 07:40:26</sys_created_on>
<sys_id>99a9a856dbd0630081d2f36f29961912</sys_id>
<sys_mod_count>1</sys_mod_count>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2018-09-04 08:15:11</sys_updated_on>
<u_name_of_the_field>caller_id</u_name_of_the_field>
<u_name_of_the_table>incident</u_name_of_the_table>
</u_totestfieldnametype>
</xml>
 
 
 
 
On the contrary if I would use a "real" Reference type pointing to a Table in the sys_db_object, then it would look like:
 
 
<u_table_by_reference_type display_value="Problem"name="problem">43bcd95d5d521300651727c3e282e8ce</u_table_by_reference_type>
 
 
This "real" one clearly has a display value in the opening Tag!
 
So how can I get the Display Value (Label) of a "Table Name" type field?
5 REPLIES 5

Omkar Mone
Mega Sage

Hi 

Try with getValue() only once.

danielnagy
Giga Contributor

As I mention in the article I tested this with getValue, like this small background script:

var tableGR = new GlideRecord('u_totestfieldnametype');
tableGR.query();
while (tableGR.next()) {
var name = tableGR.u_name_of_the_table;
var value = tableGR.getValue('u_name_of_the_table');
gs.info('Name / Value: ' + name + ' / ' + value);
}

 

And the result is:

*** Script: Name / Value: task / task
*** Script: Name / Value: change_request / change_request
*** Script: Name / Value: incident / incident



You see? It just won't give back any other value than its internal name, like "change_request".


 

 

So my guess is that "Table Name" and " Field Name" field types are not implemented correctly.

 

Hi 

Just go with tableGR.u_name_of_the_table.value from the above code. 

Else i guess it is configured incorrectly.

 

Luke Van Epen
Tera Guru

Here's the answer:

You need to query the sys_db_object table, i.e. the table of tables, and get the Label of the table, using it's name to query for it.

var tableName = current.u_name_of_the_table.getValue();

var dbo = new GlideRecord('sys_db_object');

dbo.addQuery('name', tableName);

dbo.query();

if(dbo.next()){

var displayName = dbo.getValue('label');

}​