在设置子网格

时间:2016-11-09 12:58:07

标签: javascript dynamics-crm-2016 subgrid

我已经按照代码段在发票表单上设置了子网格的fetchxml,但它抛出了异常:无法读取未定义的属性“SetParameter”

任何想法如何解决它。

代码段:

function filterUsers() {
    try {
        debugger;
        var orderId = Xrm.Page.getAttribute("salesorderid").getValue()[0].id;
        var spGrid = getSubgrid("new_salesperson");
        //var spGrid = Xrm.Page.getControl("new_salesperson");
        if (spGrid == null || spGrid == 'undefined') {
            setTimeout(filterUsers, 500);
            return;
        }
        else {
            var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                    "  <entity name='systemuser'>" +
                    "    <attribute name='fullname' />" +
                    "    <attribute name='title' />" +
                    "    <attribute name='address1_telephone1' />" +
                    "    <attribute name='systemuserid' />" +
                    "    <order attribute='fullname' descending='false' />" +
                    "    <link-entity name='new_salesorder_systemuser' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
                    "      <link-entity name='salesorder' from='salesorderid' to='salesorderid' alias='ab'>" +
                    "        <filter type='and'>" +
                    "          <condition attribute='salesorder' operator='eq' value='" + orderId + "' />" +
                    "        </filter>" +
                    "      </link-entity>" +
                    "    </link-entity>" +
                    "  </entity>" +
                    "</fetch>";
            spGrid.control.SetParameter("fetchXml", fetchXml);
            spGrid.control.SetParameter("effectiveFetchXml", fetchXml);
            spGrid.control.SetParameter("fetchXmlForFilters", fetchXml);
            spGrid.control.refresh();
        }
    }
    catch (e) {
        if (e.message == "Cannot read property '0' of null" || e.message == "orders[0] is undefined" || e.message == "Unable to get property '0' of undefined or null reference")
            return;
        alert("Error: " + e.message);
    }

}

function getSubgrid(elementName) {
    debugger;
    if (document.getElementById(elementName) == null || document.getElementById(elementName) == 'undefined') {
        return window.parent.document.getElementById(elementName);
    }
    else {
        return document.getElementById(elementName);
    }
}

1 个答案:

答案 0 :(得分:3)

不支持直接在CRM中操作DOM。找另一种方式。

在我看来,您正在尝试将一个用户子网格添加到发票表单中。用户已使用您的自定义关系new_salesorder_systemuser与销售订单相关联。

我建议您只需使用子网格用户创建一个销售订单的快速查看表单,然后选择仅相关记录。然后,您可以将此快速查看表单添加到发票表单中。