1

I'm in an odd situation, I need to generate a paging cookie for CRM that would ordinarily be generated by the CRM Service (more on why below) however I can't find it's schema or any documentation covering it.

The format I've deduced is as follows, can anybody confirm it's complete?:

<cookie page="{page no#}">
    <{first sort column logical name} first="{value of first returned items sort column - format unknown}" last="{value of last returned items sort column - format unknown}" />
</cookie>

My situation is I've written a RetrieveMultiple plugin which returns a pseudo entity which actually exists in an external database, since the organisation service isn't fetching the data I cannot rely on CRM to provide this value for me.

The paging cookie is required to iterate over OData queries, even though it will be completely ignored by my plugin which is free to use its own logic, I'm being cought by the validation message WHENEVER I include a skip querystring parameter:

[-2147220715]: Paging cookie required to retrieve more records. Update your query to retrieve with total records below 5000

Is there any way to suppress this error message?

Dead.Rabit
  • 1,914
  • 1
  • 25
  • 44
  • I'm not sure how to get around this error, but if your CRM OData query will have 5,000 or less records you can try using the $top parameter: http://msdn.microsoft.com/en-us/library/gg309461.aspx#BKMK_top – Jason Faulkner Nov 07 '14 at 00:59
  • OData is limited to 50 records IIRC, I need to retrieve all records in a loop unfortunately. Whenever I use the $skip parameter it seems to cause this error (so my first query works with just $top, but subsequent queries require the cookie). At the moment I believe my only alternative is to use FetchXML through JavaScript which I hope might not face the same validation requirements – Dead.Rabit Nov 07 '14 at 09:23
  • You can try increasing the number of records returned per page. Just be aware this would be a global setting and not specific to your application. http://blogs.msdn.com/b/crminthefield/archive/2012/03/16/how-to-increase-the-50-record-page-limit-on-odata-retrieve-responses-for-dynamics-crm-2011.aspx – Jason Faulkner Nov 07 '14 at 13:56
  • thanks for the suggestion, but this customisation should NEVER EVER EVER be done in a production environment. Also though this change would enable me to retrieve more then 50 records, even if I set it to 100,000 (though this likely wouldn't work due to server limitations on message sizes) if there were more then 100,000 records I'll still encounter the problem. – Dead.Rabit Nov 07 '14 at 14:36
  • I agree it should be used with caution (hence the warning it is not specific to your application). You can try using FetchXML but if you are ever going to have more than 5,000 records then I don't know if there is going to be a _supported_ way to do what you are looking for. – Jason Faulkner Nov 07 '14 at 14:52

1 Answers1

3

I have done an investigation into the paging cookie format, these are my findings, I will update these findings time permitting if new features become apparent.

The paging cookie is an HTML encoded string, I'd love to write this up as a proper schema if I had the time but for now a functional design will have to do:

  • "cookie" is the root element
  • "cookie" has a single int attribute "page", which is the page no#, counting from 1
  • the child nodes of "cookie" are the logical names of the order fields, complex types are also suffixed with "name", i.e: "owneridname", "statecodename"
  • These child nodes have 4 potential attributes but only 2 will be present
  • "first"/"last" are the text/name values from the sort column of the first and last result record respectively, i.e: first=&quot;Active&quot; last=&quot;Inactive&quot;
  • the alternative parameters "firstnull" and "lastnull" will always be "1" if present, they replace either the "first"/"last" attribute respectively and indicate the first value of the sort column from the result set was null and vice versa
  • there is one final child node of "cookie" which is named for the primary key field on the queried entity, it also contains first/last attributes but these are set to the GUID ID of the records surrounded in "{}" braces
  • ADDED: if the first and last values are long strings, their values are trimmed to 2000 characters before the string is encoded
  • ADDED: the first and last values are double HTML encoded, e.g: line feeds are &amp;#xA;
Community
  • 1
  • 1
Dead.Rabit
  • 1,914
  • 1
  • 25
  • 44