我下面的代码片段设置了发票表单上的子网格的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);
}
}
不支持在CRM中直接操作DOM。另寻出路。
在我看来,您正在尝试将用户的子网格添加到发票表单。用户已与您的自定义关系new_salesorder_systemuser
的销售订单相关联。