retrieveMultiple is only getting 10 records

Jul 17, 2014 at 5:27 AM
Hi,

For some reason my query is only getting 10 results. Here is the query:
    var records = null;
    XrmServiceToolkit.Rest.RetrieveMultiple("New_countrySet",
        "$select=*",
        function (results) {
            records = results;
        },
        function (error) {
             equal(true, false, error.message);
        },
        function onComplete() { },
        false);
Any ideas?
Jul 17, 2014 at 10:48 PM
This is only happening to some entities and not others.

I have looked at the data inside sql manager (there is around 300 records) and there is no noticeable difference that should make this happen. It gets the last 10 records that were imported and it also retrieves any new records I create. Very strange behaviour.
Jul 19, 2014 at 1:49 PM
I discovered what I was doing wrong. As retrieve multiple only gets 50 records at a time, I was overwriting records each time with the latest data received, and the last bundle happened to be 10.

I updated my query to add results to an array and all was solved.
Coordinator
Jul 22, 2014 at 1:56 PM
Hi.

Glad to know you sorted it out.

Kind Regards,
Jaimie
Aug 11, 2015 at 8:50 AM
Hi Can you give me an example to return > 50 records. I can't seem to page through the data using successBatchCallBack

Here is my function (only returning 50 results)

function GetSystemAccounts (id) {
XrmSvcToolkit.retrieveMultiple({ 
    entityName: "Account", 
    async: false, 
    odataQuery: "?$filter=StateCode/Value eq 0 and ParentAccountId/Id eq (guid'" + id + "')", 
    // 50 results returned per call
    successCallback: function (result) { 
        accounts = result; 
    },
    errorCallback: function (error) { 
       alert("Error");
       return;
    } 
});
return accounts; 
}
Aug 11, 2015 at 11:40 PM
The successCallback will only retrieve 50 results at a time. You need to append the result in successCallBack to another array. The following should fix your issue:
var accounts = new Array();
XrmSvcToolkit.retrieveMultiple({ 
    entityName: "Account", 
    async: false, 
    odataQuery: "?$filter=StateCode/Value eq 0 and ParentAccountId/Id eq (guid'" + id + "')", 
    // 50 results returned per call
    successCallback: function (result) { 
       for (var i = 0; i < results.length; i++) {
          accounts.push(results[i])
       }
    },
    errorCallback: function (error) { 
       alert("Error");
       return;
    } 
});
return accounts; 
Note the variable accounts is created outside the retrieveMultiple method and the results are added to it, which will be 50 at a time.