Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get field label from field name?

tahnalos
Kilo Sage

For any field in a GlideRecord, what is the method used to grab the label name?

Thanks

11 REPLIES 11

TzachB
Giga Contributor

hey,

try to use gr.[field name].getLabel();

Twist: I'm being fed a bunch of field names through an array, and I need to get the field labels for them.  How do I leverage getLabel to get the label from an array that is dynamically passed?

Well, in that case iterate over the array (let's call it arrFields) and use 

gr.getElement(arrFields[i]).getLabel();


If this post was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel

Worked like a charm!