Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are composite joins possible using FetchXml in Microsoft Dynamics CRM 4.0?

I am using FetchXml to query CRM 4.0. We have a special case that will require a composite join between CRM entites. The FetchXml schema indicates that multiple link-entity elements are allowed, and it also indicates that multiple filter/condition elements can be added to a link-entity. The problem I'm facing is that the value attribute of the condition element does not appear to permit an entity/column name. It expects an explicitly declared value.

For example, FetchXml lets you specify this:

<link-entity name='myentity' from='column1' to='column2'/>

... which does the T-SQL equivalent of this:

JOIN myentity on column1 = column2

And it lets you specify this:

<link-entity name='myentity' from='column1' to='column2'>
   <filter type='and'>
      <condition attribute='column3' operator='eq' value='myvalue' />
   </filter>
</link>

... which is the T-SQL equivalent of this:

JOIN myentity on column1 = column2 AND column3 = 'myvalue' 

FetchXml does not appear, however, to provide an equivalent of this:

JOIN myentity on column1 = column2 AND column3 = column4 

Note the difference. FetchXml provides for conditions in the join, but it does appear to provide for a composite join, that is, a join across multiple columns.

Has anyone out there in cyberspace been able to perform a composite join using FetchXml in CRM 4.0? Thanks!

More information:

I'm hunting an answer that uses FetchXml to accomplish this - not SQL or the QueryExpression syntax. The SQL above is there just to explain the concept.

like image 381
WiregrassCoder Avatar asked Oct 28 '10 19:10

WiregrassCoder


People also ask

What is the difference between FetchXML and QueryExpression?

The main difference is that fetchXML support aggregation whether query expression does not support aggregation. Secondly we will use Query expression when our query is complex and its server side coding , where as fetch XML is easy to build and easy to use and you can write both server side and client side as well.

What is FetchXML in MS CRM?

FetchXML is a proprietary XML based query language of Microsoft Dataverse used to query data using either the Web API or the Organization service. It's based on a schema that describes the capabilities of the language. The FetchXML language supports similar query capabilities as query expressions.

How do I use link entity in FetchXML?

All the link entities are highlighted in the Advanced Find, now let's click on Download Fetch XML in order to get our required XML. After getting our XML, we can see that our related field Survey is now in a link-entity tag with pre-defined attributes like from, to, link-type and alias.


1 Answers

No, it doesn't permit this. Fetch XML is pretty limited when it comes to anything non-basic in joins. If I'm curious I usually test my query using Stunnware Tools. If it is not exposed there it probably can't be done.

Unfortunately, in situations like these these I usually end up (am forced into) taking a multiple query approach to the problem.

I know you said you're not interested in this - but I'm pretty sure QueryExpression won't handle it either. In my experience it only offers a subset of the fetchxml functionality.

like image 141
John Hoven Avatar answered Sep 17 '22 15:09

John Hoven