1

I get this error.

Error : 500: Internal Server Error: Queries with valid paging cookie should not be executed in this strategy

when I invoke this code in a WebResource in CRM 2011

    self.loadWorkItems = function () {

        var user = self.user();
        var bid = user.BusinessUnitId.Id();
        var systemUserId = user.SystemUserId();
        var results = new Array();


        SDK.REST.retrieveMultipleRecords(
            "QueueItem",
            "$select=*&$skip=" + self.page() * self.pageSize() + "&$top=" + self.pageSize() + "&$orderby=CreatedOn asc&$filter=OwningBusinessUnit/Id eq guid'" + bid + "' and StateCode/Value eq 0",
            function (r) {
                results = results.concat(r);
            },
            function (error) {
                self.lastError(error.message);
            },
            function (x) {
                for (var i = 0; i < results.length; i++) {
                    var item = results[i];
                    var r = ko.mapping.fromJS(item, workItemMapping);
                    self.workQueue.push(r);
                }
            }
        );
    };

this is part of a knockoutjs viewmodel. I am trying to make a "More" button that goes and gets the next page of data from the server and throws it on the end of the list being displayed.

The page loads just fine and the first page comes back but when the next page is requested I get this error.

Any ideas on how to make the call without the error?

EDIT

I was mistaken It seems that some calls with $skip > 0 work. Going crazy here.

EDIT

I think what this error is trying to tell me is that the skip/top combo is more than the total record count and instead of giving me nothing (as I would expect), it's throwing an exception.

So the new question is how to avoid this stupidity? I guess now I have to count all the records and and make sure I don't page too much.

Peter
  • 7,792
  • 9
  • 63
  • 94
  • sounds like you're on the right track. If you're running this without knowing the result set, perhaps you can run a Count query first and then run this based on the size result of the Count? – Mike_Matthews_II Mar 18 '13 at 15:38

2 Answers2

2

We deliberately catch all errors when performing query's since the SDK has a bug in the skip and take linq query's which is causing issues when skipping more then the result has items. As far as i know this isn't fixed by Microsoft yet

on5sl
  • 51
  • 8
0

You fetch an non existing "page". Basically you are skipping more element than the result has.

So lets say that the underlying result in total have 10 records that match your filter and you say

query.skip(12) then you get this situation.

Kjeld Poulsen
  • 213
  • 3
  • 4