Dynamics CRM odata query data with more than 50 records (retrieving more than 50 records using odata)

Source: Internet
Author: User

When you use oddata to obtain CRM data, the default query result contains only 50 records. You can use the "_ next" attribute in the object returned by JSON as a URL loop until the property is empty.


The sample code is as follows:

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

The sample code in this article is taken from the blog:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.