- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 05:31 AM - edited 04-30-2025 05:37 AM
I've two fields in a custom table.
Field A -> type = table_name
Field B -> type = field_name (which is dependent on Field A)
This will list out all columns of child as well as parent table which is good. However, whenever a new record is created into this table, I need to know the internal_name of the Field B (it works fine if Field B is part of child table but runs into problem when it's from parent)
For example, if I select "Incident" in Field A and "Additional Comments" (which is present in parent Task and not incident) in Field B, what would I write in the "insert" BR to know the internal_name of "comments" which return "Journal"
Because if I write the following in the BR
var dictionaryEntry = new GlideRecord('sys_dictionary');
dictionaryEntry.addQuery('name', current.table);
dictionaryEntry.addQuery('element', current.column);
dictionaryEntry.query();
if (dictionaryEntry.next()) {
gs.print(dictionaryEntry.internal_type.label);
}
it won't go into the "if" block because current.table (incident) and current.column (comments) is not valid.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 05:58 AM
you will have to check if that field is extended one from parent table
try this
// Function to get the internal name of the field
function getInternalName(tableName, fieldName) {
var dictionaryEntry = new GlideRecord('sys_dictionary');
dictionaryEntry.addQuery('name', tableName);
dictionaryEntry.addQuery('element', fieldName);
dictionaryEntry.query();
if (dictionaryEntry.next()) {
return dictionaryEntry.internal_type.label;
} else {
// Check if the table has a parent table
var tableGR = new GlideRecord('sys_db_object');
tableGR.addQuery('name', tableName);
tableGR.query();
if (tableGR.next() && tableGR.super_class) {
// Recursively check the parent table
return getInternalName(tableGR.super_class.name, fieldName);
} else {
return null;
}
}
}
// Get the internal name of the field
var internalName = getInternalName('incident', 'comments');
if (internalName) {
gs.info('Internal Name: ' + internalName);
} else {
gs.info('Field not found in the table hierarchy.');
}
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 05:58 AM
you will have to check if that field is extended one from parent table
try this
// Function to get the internal name of the field
function getInternalName(tableName, fieldName) {
var dictionaryEntry = new GlideRecord('sys_dictionary');
dictionaryEntry.addQuery('name', tableName);
dictionaryEntry.addQuery('element', fieldName);
dictionaryEntry.query();
if (dictionaryEntry.next()) {
return dictionaryEntry.internal_type.label;
} else {
// Check if the table has a parent table
var tableGR = new GlideRecord('sys_db_object');
tableGR.addQuery('name', tableName);
tableGR.query();
if (tableGR.next() && tableGR.super_class) {
// Recursively check the parent table
return getInternalName(tableGR.super_class.name, fieldName);
} else {
return null;
}
}
}
// Get the internal name of the field
var internalName = getInternalName('incident', 'comments');
if (internalName) {
gs.info('Internal Name: ' + internalName);
} else {
gs.info('Field not found in the table hierarchy.');
}
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 04:37 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 09:21 PM
I like that it is recurssive in nature. We could have multi level inheritance for some tables.