设置子网格的 fetchXML 时无法读取 Dynamics CRM 中未定义的 属性 'SetParameter'

Cannot read property 'SetParameter' of undefined in Dynamics CRM while setting up fetchXML of a subgrid

我按照以下代码片段在发票表单上设置子网格的 fetchxml,但它抛出异常:无法读取未定义的 属性 'SetParameter'[=21] =].

知道如何解决它。

代码段:

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

不支持直接在 CRM 中操作 DOM。另辟蹊径。

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

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