Build queries with FetchXML

Applies to Dynamics 365 (online), version 9.x

FetchXML is a proprietary query language that is used in Dynamics 365 (online) Customer Engagement. It’s based on a schema that describes the capabilities of the language. The FetchXML language supports similar query capabilities as query expressions. In addition, it’s used as a serialized form of query, used to save a query as a user-owned saved view in the UserQuery Entity and as an organization-owned saved view in the SavedQuery Entity.

Execute queries in code

A FetchXML query can be executed by using either the Web API or the Organization service.

Web API

You can pass a URL encoded FetchXml string to the appropriate entityset using the fetchXml query string parameter. More information: Use custom FetchXML.

Organization service

Use the IOrganizationService.RetrieveMultiple method passing an FetchExpression where the Query property contains the FetchXml query.

You can convert a FetchXML query to a query expression with the FetchXmlToQueryExpressionRequest message.

Tools

The XrmToolBox FetchXML Builder provides a user interface to compose and execute FetchXml queries.

Note

The XrmToolBox FetchXML Builder is not a product of Microsoft Dynamics and does not extend support to it. If you have questions pertaining to the FetchXML Builder, please contact the publisher.

Advanced Find includes the capability to download the FetchXML for the query using the Dowload Fetch XML command. More information: Create, edit, or save an Advanced Find search

In This Section

Use FetchXML to Construct a Query
Use FetchXML Aggregation
Page Large Result Sets with FetchXML
Fiscal Date Query Operators in FetchXML
Use a left outer join in FetchXML to query for records not in
Sample: Use Aggregation in FetchXML
Sample: Use FetchXML with a Paging Cookie
Sample: Convert Queries Between Fetch and Query Expression
Sample: Validate and execute a saved query

Build queries with LINQ (.NET language-integrated query)
Build queries with QueryExpression
Retrieve Records for Many-To-Many Relationships using Intersect Entities
FetchXML schema