Dynamics CRM 2015 Online:SubGrid的control.SetParameter方法不可用

时间:2015-09-14 12:01:53

标签: javascript dynamics-crm dynamics-crm-2015

我正在尝试使用CRM 2015在线填充带有fetchXml结果的子网格。一开始的一个问题是document.getElementById("leadUmbrellaGrid");返回null

function filterSubGrid() {

    var leadwithSameNameGrid = Xrm.Page.getControl("leadUmbrellaGrid").getGrid();//HAVE TRIED window.parent.document.getElementById("leadUmbrellaGrid"); //grid to filter
    var currentleadId = Xrm.Page.data.entity.getId();;
    if (leadwithSameNameGrid == null) {

        setTimeout('filterSubGrid()', 500);
        return;
    }
    //fetch xml code 
    var fetchXml = "<fetchxml goes here>";


    leadwithSameNameGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid   
    leadwithSameNameGrid.control.refresh(); //refresh the sub grid using the new fetch xml

}

我经历了thisthis

我也试过了window.parent.document.getElementById,但在这两种情况下,.control都是null或未定义,最终得到:

TypeError:无法获取未定义或空引用的属性“SetParameter”

非常感谢您的帮助/提示。 谢谢,

2 个答案:

答案 0 :(得分:6)

以下是解决方案:

  1. 我们需要使用window.parent.document.getElementById

  2. 等待control加载DOM。

  3. 所以代码看起来像这样:

    function filterSubGrid() 
    {
    
        var leadwithSameNameGrid = window.parent.document.getElementById("leadUmbrellaGrid");
        var currentleadId = Xrm.Page.data.entity.getId();;
        if (leadwithSameNameGrid == null) 
        {
            setTimeout(filterSubGrid, 500);
            return;
        }
    
        //fetch xml code 
        var fetchXml = "<fetchxml goes here>";
        if (leadwithSameNameGrid.control != null) 
        {
            leadwithSameNameGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid   
            leadwithSameNameGrid.control.refresh(); //refresh the sub grid using the new fetch xml
        } 
        else 
        {
            setTimeout(filterSubGrid, 500);
        }
    }
    

答案 1 :(得分:1)

function filterSubGrid() {

        var leadwithSameNameGrid = window.parent.document.getElementById("leadUmbrellaGrid");
        var currentleadId = Xrm.Page.data.entity.getId();;
        if (leadwithSameNameGrid == null) {

            setTimeout('filterSubGrid()', 500);
            return;
        }
        //fetch xml code 
        var fetchXml = "<fetchxml goes here>";
        if (relatedProjectsSubGrid.control != null) {
        leadwithSameNameGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid   
        leadwithSameNameGrid.control.refresh(); //refresh the sub grid using the new fetch xml
          } else {
        setTimeout('filterSubGrid()', 500);
        }

    }

我已经尝试了这个,但没有得到你在哪里获得&#34; relatedProjectsSubGrid.control&#34;,这也适用于CRM 7.1吗? 感谢