Get a GlideRecord column by its label

Nam Nguyen
Tera Expert

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?

6 REPLIES 6

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


juancarvajal
Tera Contributor

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