-2

I need to get all controls from a tab on my form, I tried to use this option I found online but it didn't work ideas anyone?

var tabs = Xrm.Page.ui.tabs.get(); 
var fieldList = new Array();
for (var i in tabs)
{
  var tab = tabs[i];
  if(tab.getName() == "tab_2")
  {
    tab.sections.forEach(function (section, sectionIndex)
    {
      section.controls.forEach(function (control, controlIndex)
      {
        switch (control.getControlType())
        {
          case "standard":
          case "lookup":
          case "optionset":
            var attribute = control.getAttribute();

            if (attribute != null)
            {
              fieldList.push(attribute.getName());
            }
            break;
          }
        });
      });
    }
  }
} 
jasonscript
  • 6,039
  • 3
  • 28
  • 43
Damkulul
  • 1,406
  • 2
  • 25
  • 59

1 Answers1

0

I just tried the code and it works. It looks for a tab called tab_2 and then gets all controls within that tab and adds the control.name to an array (fieldList)

The result is a simple array of control names. When I ran this on my Contact form (with the Tab Name adjusted) I got the following results:

[
    "fullname",
    "nickname",
    "employeeid",
    "jobtitle",
    "parentcustomerid",
    "emailaddress1",
    "telephone2",
    "telephone1",
    "mobilephone",
    "fax",
    "address1_composite",
    "preferredsystemuserid",
    "familystatuscode",
    "spousesname",
    "birthdate",
    "description",
    "ownerid",
    "createdon"
]

If this is not working for you, I suggest the following:

  • Check the name of the CRM Tab
  • Depending on where you are running this (e.g. in a web resource or developer console) you may need to change the code context
jasonscript
  • 6,039
  • 3
  • 28
  • 43