Script: How to get all fields from another existing table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 06:33 AM
Can anyone provide some code snippet how to get all field names/labels from another existing table?
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 06:49 AM
Here is an example that returns all the fields of a record who has a value
var grINC = new GlideRecord('incident');
grINC.query();
grINC.next();
gs.print('Using ' + grINC.getValue('number'));
gs.print('');
// getFields() returns a Java ArrayList
var fields = grINC.getFields();
// Enumerate GlideElements in the GlideRecord object that have values
gs.print('Enumerating over all fields with values:');
for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
gs.print(' ' + glideElement.getName() + '\t' + glideElement);
}
}
gs.print('');
Source: http://wiki.servicenow.com/index.php?title=GlideRecord#getFields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 03:18 AM
Thanks dvp
Unfortunatelly I don't have "correct answer" button.
Gyazo - 3c9a6e738fc40f1f2cf6b5aa0586d670.png

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 03:35 AM
Unfortunatelly I don't have "correct answer" button.
By this comment people will know that the issue has been addressed