我有这段代码:
function FilterCasesSubgrid() {
//var CasesSubgrid = Xrm.Page.getControl("contact").getGrid();
var CasesSubgrid = window.parent.document.getElementById("contact");
if(CasesSubgrid==null){
setTimeout(function () { FilterCasesSubgrid(); }, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='contact'>"+
"<attribute name='fullname' />"+
"<filter type='and'>"+
"<condition attribute='fullname' operator='eq' value='s%' />"+
"</filter>"+
"</entity>"+
"</fetch>";
//Here i set the fetchxml directly to subgrid
CasesSubgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
CasesSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
}
错误:
TypeError:无法读取属性&#39; SetParameter&#39;未定义的 FilterCasesSubgrid
答案 0 :(得分:1)
此代码不受支持,因此您不应期望它能够正常工作。使用任何直接访问DOM的函数(即window.parent.document.getElementById
)或使用MSDN SDK中未定义的函数都是不受支持的,应该避免使用。
但是,鉴于你似乎只是在添加一个过滤器,所以有一些支持的方法可以通过设置现有的FetchXML查询来实现:
var myView = {
entityType: 1039, // SavedQuery
id:"{3A282DA1-5D90-E011-95AE-00155D9CFA02}",
name: "My Custom View"
}
//Set the view using ContactsIFollow
Xrm.Page.getControl("Contacts").getViewSelector().setCurrentView(myView);
答案 1 :(得分:0)
您需要等待 AND 元素控件属性(CasesSubgrid.control)。
已经回答here
答案 2 :(得分:0)
以下是解决方案:
所以代码看起来像这样:
function FilterCasesSubgrid()
{
//var CasesSubgrid = Xrm.Page.getControl("contact").getGrid();
var CasesSubgrid = window.parent.document.getElementById("contact");
if(CasesSubgrid==null)
{
setTimeout(function () { FilterCasesSubgrid(); }, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='contact'>"+
"<attribute name='fullname' />"+
"<filter type='and'>"+
"<condition attribute='fullname' operator='eq' value='s%' />"+
"</filter>"+
"</entity>"+
"</fetch>";
//Here i set the fetchxml directly to subgrid
if(CasesSubgrid.control != null)
{
CasesSubgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
CasesSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
}
else
{
setTimeout(CasesSubgrid, 500);
}
}
&#13;