Friday, September 6, 2013

MS CRM 2011 UR14 Breaking Change: FetchXML count="-1" does not return any records

A change in the interpretation of FetchXML "count" attribute has been identified from Update Rollup 14 for Microsoft Dynamics CRM 2011.

In many situations when you use FetchXML you have the need to return all records available, instead of using paging or in other ways limiting the number of records returned.
Up until now, we have regularly used the method of setting the count attribute to “-1” to indicate “all records”.

<fetch count="-1" mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="name" />
    <attribute name="address1_city" />
  </entity>
</fetch>
This is however not a good idea if you are running CRM with UR 14. Instead, this will not return any records at all!
Setting the count attribute to “0” or completely omitting the count attribute will return all records (up to the internally set limit, typically 5000).

<fetch count="0" mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="name" />
    <attribute name="address1_city" />
  </entity>
</fetch>
In the documentation of the FetchXML syntax it is not stated how to use the count attribute to instruct CRM to return all records, and maybe it is just us who ignorantly have used the “-1” value until now and just us who consider the change to be “breaking”… but somehow, I don’t really think so.