Get a GlideRecord column by its label
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2017 04:45 PM
Hi folks,
I have 2 tables similar columns that I want to copy from one to the other, but they only have the same label and not the name
For example:
table: cmdb_model
column: u_rpm
column label: RPM
u_hardware
column: u_en_rpm
column label: RPM
Is there a way to dynamically refer to those fields by matching the column labels?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2017 05:14 AM
Thanks for the update. If you've got your answer, don't forget to mark the appropriate response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 02:35 PM
I did something similar, try to use this code
function getFieldLabel(table, field) {
var rec = new GlideRecord(table);
rec.initialize();
var fields = rec.getFields();
for(var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
//if it finds the same name return the label
if(glideElement.getName() == field)
return glideElement.getLabel();
}
}
And you can use it like getFieldLabel('cmdb_model', 'u_rpm');
In your case you can modify it to find by the label and not by the name and return that field