问题描述:

I have a subgrid named TimeTickets, I try:

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

var ids = gridControl.get_allRecordIds();

but I get the following error:

Object doesn't support property or method 'get_allRecordIds'

Notes:

  • CRM Rollup Update 13
  • Browser: Internet Explorer 9

网友答案:

I solved in this way:

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();
网友答案:

As the error states the method get_allRecordIds is not supported for that particular control. I would guess that Microsoft MAY have changed the structure of the HTML meaning that its not looking at the correct control.

I'd suggest you use this instead

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

EDIT As mentioned by anykey3 this solution doesn't appear to work all the time either. I have it working on CRM Online however CRM on premise doesn't seem to work correctly. One solution I have that works is using the RESTful service which might not be the best solution as it requires ALOT more code.

    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
        }
    }
}
网友答案:

check this code its working fine in dynamics 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);
    }}
相关阅读:
Top