// Get a single incident record 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('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(''); // Get a specific GlideElement: number gs.print('Getting the number field:'); for (var i = 0; i < fields.size(); i++) { var glideElement = fields.get(i); if (glideElement.hasValue() && glideElement.getName() == 'short_description') { gs.print(' ' + glideElement.getName() + '\t' + glideElement); } }
Output:
How to get All fields name and values using single GlideRecord ServiceNow (getFields() Method)