Loop through all var fields in Catalog Client Script

grosch
Mega Expert

In a catalog client script I want to widen all of my reference fields, so I'm using code like this:

 

function onLoad() {
   var fields = ['STT_Opera_service', 'STT_Opera_component', 'STT_Opera_operations_lead', 'STT_Opera_opsTransitionLead'];
   for (var i = fields.length - 1; i >= 0; i--) {
   var varCon = g_form.getControl(fields[i]);
   var field = gel("sys_display."+ varCon.id);
   field.style.width = '350px';
   }
}

 

Is there a way to not hardcode those names, and instead just loop through all the fields defined on the form and just grab the ones of type Reference?   The above works just fine...right up until I rename a variable, or delete one, or add a new one, or....

2 REPLIES 2

justin_drysdale
Mega Guru

Using pure DOM methods:



          var fields = document.getElementsByClassName('questionsetreference');
          for (var i = fields.length - 1; i >= 0; i--) {
              fields[i].style.width = '350px';
          }



This works in Calgary.   If you are using a different version you would need to get the class name of reference fields and replace 'questionsetreference' with your instance's reference field class name.



document.getElementsByClassName - Web API Interfaces | MDN


This is perfect, thank you!