Search code examples
pluginsdynamics-crmcrmdynamics-crm-2013

Generate Paging Cookie for CRM RetrieveMultiple Plugin


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?


Solution

  • 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;