如何使用javascript在CRM 2011中检索子网格的所有记录ID

时间:2013-07-15 10:12:18

标签: dynamics-crm-2011 dynamics-crm crm

我有一个名为TimeTickets的子网格,我尝试:

var gridControl = document.getElementById('TimeTickets_d').control;
var ids = gridControl.get_allRecordIds();

但是我收到以下错误:

  

Object不支持属性或方法'get_allRecordIds'

注意:

  • CRM Rollup Update 13
  • 浏览器:Internet Explorer 9

3 个答案:

答案 0 :(得分:1)

我这样解决了:

var grid = Xrm.Page.ui.controls.get('TimeTickets')._control;

if (grid.get_innerControl() == null) {
    setTimeout(subGridOnload, 1000);
    return;
}
else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) {
    setTimeout(subGridOnload, 1000);
    return;
}

var ids = grid.get_innerControl().get_allRecordIds();

答案 1 :(得分:0)

由于错误声明该方法不支持该特定控件的get_allRecordIds。我猜想微软可能已经改变了HTML的结构,这意味着它没有看到正确的控制。

我建议你改用

Xrm.Page.ui.controls.get('TimeTickets')._control.get_innerControl().get_allRecordIds();

EDIT 正如anykey3所提到的,这个解决方案似乎并不总是有效。我有它在CRM Online工作,但CRM内部部署似乎不能正常工作。我所使用的一个解决方案是使用RESTful服务,这可能不是最好的解决方案,因为它需要更多的代码。

    function GetChildrenValues()
    {
    if (Xrm.Page.data.entity.getId() != null)
    {
        var odataFieldName = "ContactSet";
        var identifier = new Array();
        identifier[0] = Xrm.Page.data.entity.getId();

        var context = Xrm.Page.context;
        var serverUrl = context.getServerUrl();
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

        var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + '?$filter=accountid eq {GUID}';


        odataUri +=  '?$filter=accountid eq {GUID}';

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: odataUri,
            beforeSend: function (XMLHttpRequest) {
                //Specifying this header ensures that the results will be returned as JSON.             
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, textStatus, XmlHttpRequest) {
                SuccessCallback(data, textStatus, XmlHttpRequest);
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                // Handle Error
            }
        });
    }
}

function SuccessCallback(data, textStatus, XmlHttpRequest)
{
    if (data.length > 0) {
        var total = 0;

        for (var i = 0; i < data.length; i++) {
            // Do something
        }
    }
}

答案 2 :(得分:0)

检查此代码在动态crm 2013中的工作正常

function RetrieveSubGridRecords() {
debugger;
    if (document.getElementById("Contacts")) {
        var grid = document.getElementById("Contacts").control;
        for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
            for (var cellNo = 0; cellNo < grid.GetRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
                alert(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);    }    else {
        setTimeout("RetrieveSubGridRecords();", 2500);
    }}