码迷,mamicode.com
首页 > 其他好文 > 详细

Dynamics CRM OData 查询超过50条记录的数据(Retrieving More than 50 records using OData)

时间:2014-07-12 19:16:08      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:dynamics crm   retrieve   odata   

在通过ODdata方式获取CRM数据时,默认查询出来的results只有50条数据,可以通过JSON返回的Object中的“_next”属性作为URL循环获取直到该属性为空

bubuko.com,布布扣

示例代码如下:

relatedAccounts = [];

function onload() {
    var serverUrl = Xrm.Page.context.getServerUrl();
    var oDataUri = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet?$select=AccountId,Name,&$filter=StateCode/Value eq 0";
    GetRecords(oDataUri);
    var totalRecords = relatedAccounts.length;
}

function GetRecords(url) {
    jQuery.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: url,
        async: false,
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            if (data && data.d != null && data.d.results != null) {
                AddRecordsToArray(data.d.results);
                FetchRecordsCallBack(data.d);
            }
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert("Error :  has occured during retrieval of the records ");
        }
    });
}

function AddRecordsToArray(records) {
    for (var i = 0; i < records.length; i++) {
        relatedAccounts.push(records[i]);
    }
}

function FetchRecordsCallBack(records) {
    if (records.__next != null) {
        var url = records.__next;
        GetRecords(url);
    }
}

本文示例代码摘自博客:

http://lakshmanindian.wordpress.com/2012/12/07/retrieving-more-than-50-records-using-odata-in-crm-2011/

Dynamics CRM OData 查询超过50条记录的数据(Retrieving More than 50 records using OData),布布扣,bubuko.com

Dynamics CRM OData 查询超过50条记录的数据(Retrieving More than 50 records using OData)

标签:dynamics crm   retrieve   odata   

原文地址:http://blog.csdn.net/vic0228/article/details/37656459

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!