FetchXML count="-1" now returns records again

Last September I highlighted a change in the FetchXML interpretation, where using syntax like…

<fetch count="-1" mapping="logical" version="1.0">
  <entity name="account">
    <attribute name="name" />
    <attribute name="address1_city" />
  </entity>
</fetch>

…would not return any records. You had to use a count of “0” instead.
Now, when running CRM 2013, a count of “-1” returns records again 🙂
Perhaps someone in the product team happened to read my post and thought they should be nice to me.
That was kind.

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.

Xrm.Utility methods in MS Dynamics CRM UR8

  • Have you ever used the unsupported javascript-function openObj to open a form in Microsoft Dynamics CRM 2011?
  • Have you ever cursed out loud over getting correct paths and parameters for URL Addressable Forms?
  • Have you ever implemented your own functionality to open a Microsoft Dynamics CRM 2011 webresource in a new window?

Stop that. Now. At last, in UR8 Microsoft has included supported javascript-functions for those actions, providing a better user experience as well as nicer code than using the functionality of URL Addressable Forms and Views. No new SDK version has been released yet, so you cannot read about it or find any examples there, it was just recently announced in The Microsoft Dynamics CRM Blog.

Basic description

There is a javascript library called Xrm.Utility which is available “everywhere” as long as you have a CRM context.

Xrm.Utility.openEntityForm(name, id, parameters)
Xrm.Utility.openWebResource(webResourceName, webResourceData, width, height)

Both functions return the window object that is created which allows you to e.g. move and resize the window.
The parameters parameter can be used to set default values when creating a new record and to specify which form to display.
One of the best things though – is that the openEntityForm function takes the LogicalName of the entity instead of forcing us to make a metadata request to get the ObjectTypeCode…!

Usage examples

openEntityForm
  • Open a record from a custom html or Silverlight displaying CRM data
  • Open a new record form from a custom ribbon button populating with default data
  • Create a new record in javascript and then opening that new record
openWebResource
  • Open a webresource from a custom ribbon button (e.g. html page with Bing map integration)
  • Prompt user for confirmation using your own nicely styled Confirm dialog (instead of ugly styled window.confirm(…))

Thank’s Markus for enlightening me about this news!