- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 04:59 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 05:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 05:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 05:57 AM
Hi Sebastiaan,
I've tried and tested this and it works perfectly - thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 08:19 AM
Is there a way that this function can be used for Glide List fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 11:26 AM
getReferenceTable() does not work for Glide List fields, but you can use this method to find the reference table for a glide list: gliderecord.element.getED().reference. This is undocumented, but you can find this when you inspect the GlideElementDescriptor.
var inc = new GlideRecord('incident');
inc.get('number', 'INC0010096');
var tableName = inc.watch_list.getED().reference;
gs.print(tableName);
// => sys_user