Aug 26 2008
CRM4 Web Service Errors
As well as starting to work with SharePoint in the last two months, I’ve also been doing some development in Dynamics CRM4. Â In the past week I’ve been porting an ISV add-on that was written for CRM3. Â Whilst most of the code is pretty much the same, there are a few gotcha to watch out for.
The first problem I came across was the web-service authentication.  I’m not a CRM expert but I believe this has something to do with the new multi-tenancy installation option.  Now when you connect to a web service you need to create a CrmAuthenticationToken and pass it to the web service.  This allows you to specify which organisation you are connecting to.
Once connected to I started getting the following error when running a FetchXML query:
<error> Â <code>0x8004111a</code> Â <description>An aggregate operation was initially specified, but no aggregate operator was encountered.</description> Â <type>Platform</type> </error>
This error was being generated by the following FetchXML query:
<fetch mapping="logical" aggregate="true"> Â <entity name="account"> Â <filter> Â <condition attribute="accountid" operator="eq" value="edd2b749-9f58-dd11-90aa-00155d0a0e03" /> Â </filter> Â <link-entity name="contact" from="accountid" to="accountid"> Â <attribute name="contactid" aggregate="count" alias="myCount" /> Â </link-entity> Â </entity> </fetch>
The purpose of this query is to count all the contacts that are linked with a specific account. Â It does this selecting an account entity with a specific id and then counting all the contact id’s for the contacts that are linked to the account.
For some reason the xml parser finds the aggregate=”true” flag but doesn’t find the count aggregate on the linked entity. Â Quite why this works in CRM3 but not in CRM4 is beyond me but what I do know is that turning this query around works:
<fetch mapping="logical" aggregate="true">
<entity name="contact">
<attribute name="contactid" aggregate="count" alias="count" />
<link-entity name="account" from="accountid" to="accountid">
<filter>
<condition attribute="accountid" operator="eq" value="edd2b749-9f58-dd11-90aa-00155d0a0e03" />
</filter>
</link-entity>
</entity>
</fetch>
In this case the query is run against contract and the id’s are counted where they are linked to a specific account. Â I assume this works because the aggregate attribute is on the root entity. Â I haven’t tested if it is possible to add more aggregates to the link entities or not.