Script: How to get all fields from another existing table?

stryker129
Mega Guru

Can anyone provide some code snippet how to get all field names/labels from another existing table?

Thanks in advance

3 REPLIES 3

dvp
Mega Sage
Mega Sage

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


Thanks dvp


Unfortunatelly I don't have "correct answer" button.


Gyazo - 3c9a6e738fc40f1f2cf6b5aa0586d670.png


Unfortunatelly I don't have "correct answer" button.


By this comment people will know that the issue has been addressed