Monday, February 16, 2009

Working with FetchXml()


Fetch is a proprietary query language that is used in Microsoft Dynamics CRM. It is based on a schema that describes the capabilities of the language. The FetchXML language supports similar query capabilities as query expression. It is used primarily as a serialized form of query expression, used to save a query as a user owned saved view in the userquery entity or as an organization owned view in the savedquery entity. A FetchXML query can be executed by using the Fetch method. There are also messages to convert between query expression and FetchXML.

Generally, the RetrieveMultiple method performs faster than the Fetch method because it does not have to parse the query.

Microsoft Dynamics CRM 4.0 supports a new attribute on the link-entity node called visible. Setting visible to false will hide the linked entity in the advanced find user interface. It will still participate in the execution of the query and will return the appropriate results.

The following table lists the messages that work with the FetchXml language.

ExecuteFetch -> Executes a query.
FetchXmlToQueryExpression -> Converts from FetchXML to query expression.
QueryExpressionToFetchXml -> Converts from query expression to FetchXML.
ValidateSavedQuery -> Validates a saved query (view).

NOTE:
Notice that in either case, the privileges of the logged on user will affect the set of records returned. The Fetch method only retrieves records for which the logged on user has read access.

By default FetchXml returns MAX of 5000 records.

1 comment:

Weifeng Jiang said...

Thank you very much!
I think the readers of this post might interested in writing FetchXML, here is a web tool convert from SQL to FetchXML, available at http://www.sql2fetchxml.com