- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 09:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 10:20 PM
var arr_fields=[];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name','incident');
fileds.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');//To ignore all the table dictionaries(optional)
fields.query();
while(fields.next())
{
arr_fields.push(fields.column_label.toString()+"("+fields.element.toString() + ")" );
}
for(var i=0; i<arr_fields.length; i++)
{
gs.print(arr_fields[i]);
}
Please mark ot helpful and correct if it was.
Regards!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 10:20 PM
var arr_fields=[];
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name','incident');
fileds.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');//To ignore all the table dictionaries(optional)
fields.query();
while(fields.next())
{
arr_fields.push(fields.column_label.toString()+"("+fields.element.toString() + ")" );
}
for(var i=0; i<arr_fields.length; i++)
{
gs.print(arr_fields[i]);
}
Please mark ot helpful and correct if it was.
Regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2018 10:21 PM
Thanks for your great answer, it helps me a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2019 11:41 PM
Hi,
What if table has extends from other table. In above case Incident has extends from Task and if you run mentioned script it will miss the fields which are from task table like description, short_description... etc
Is there anyway to get all fields from existing table and parent table as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2022 02:52 PM
You have a typo on line 5 ("fileds") but once that's fixed the script works beautifully. Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2021 11:29 AM
The sys_dictionary table will not show inherited fields directly. (i.e. "short_description" from the task table if querying the incident table).
Use the following script to get all fields (including inherited fields) along with its Label, DB Name, and internal type.
var tableName = "alm_hardware";
var grTableData = new GlideRecord(tableName);
grTableData.setLimit(1);
grTableData.query();
grTableData.next();
var fields = grTableData.getFields();
gs.info("Label, Field Name, Internal Type");
// Enumerate GlideElements from GlideRecord
for (var i = 0; i < fields.size(); i = i + 1) {
var glideElement = fields.get(i);
var label = glideElement.getLabel();
var internalType = String(grTableData.getElement(glideElement.getName()).getED().getInternalType().toString());
var database_field_name = glideElement.getName();
gs.info("{0}, {1}, {2}", label, database_field_name, internalType);
}
//Sample Output
//*** Script: Label, Field Name, Internal Type
//*** Script: Parent, parent, reference
//*** Script: Short Description, short_description, string
//........