如何从选项卡获取所有控件

时间:2018-05-23 06:11:10

标签: dynamics-crm-2016 xrm

我需要从我的表单上的标签中获取所有控件,我尝试使用我在网上找到的这个选项但是它没有任何想法吗?

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;
          }
        });
      });
    }
  }
} 

1 个答案:

答案 0 :(得分:0)

我刚刚尝试了代码并且它有效。 它会查找名为 tab_2 的标签,然后获取该标签中的所有控件,并将control.name添加到数组(fieldList

结果是一个简单的控件名称数组。当我在我的联系表单上运行它时(调整了Tab Name),我得到了以下结果:

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

如果这不适合你,我建议如下:

  • 检查CRM标签的名称
  • 根据您的运行位置(例如在Web资源或开发人员控制台中),您可能需要更改代码上下文
相关问题