How can I determine which table a reference field references in script?

liv_cp
Giga Contributor

Within a script include I'd like to determine the field type of certain fields and, if the type is reference, which table it references.

I don't have any issues with determining the field type and can successfully determine whether a field is a reference field or not using element descriptor and getInternalType().

However, I'm not sure of the best way to determine which table the field references.

Currently, my only idea is to glide the sys_dictionary table to find the field and hence which table it references but I'm sure there must be a function somewhere that gets this in a more elegant way?

1 ACCEPTED SOLUTION

Sebastiaan de V
Kilo Guru

Hi Liv,



You can use the function getReferenceTable() of the GlideElement, see the documentation: getReferenceTable()



var grINC = new GlideRecord('incident');
grINC.query('number','INC0010041'); // record assignment group assigned to "CAB Approval"
if (grINC.next()) {
  // Get the table name
  var tableName = grINC.assignment_group.getReferenceTable();
  gs.info( tableName );
}



Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

5 REPLIES 5

Thank you for sharing this method on glide_list field.

Do you still have the source where you found it?