【问题标题】:SetParameter("fetchXml", FetchXml) doesn't support in crm 2016 onlineSetParameter("fetchXml", FetchXml) 在 crm 2016 online 中不支持
【发布时间】:2016-06-03 19:56:07
【问题描述】:

我有这个代码:

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:无法读取未定义的属性“SetParameter” 过滤案例子网格

【问题讨论】:

    标签: dynamics-crm crm dynamics-crm-online


    【解决方案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);
    

    【讨论】:

      【解决方案2】:

      您需要等待元素 AND 控件属性 (CasesSubgrid.control)。

      这已经回答here

      【讨论】:

        【解决方案3】:

        解决办法如下:

        • 我们需要使用 window.parent.document.getElementById
        • 等待控件加载到 DOM 中。

        所以代码应该是这样的:

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

        【讨论】:

        • 我有两个自定义实体 N:N 关系。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-24
        • 2021-02-19
        • 1970-01-01
        • 2016-08-09
        • 1970-01-01
        • 1970-01-01
        • 2015-10-25
        相关资源
        最近更新 更多