How to Create and Save FetchXmlQuery from Dynamics 365

How to Create and Save FetchXmlQuery from Dynamics 365

In Dynamics 365 WebAPI, you can retrieve data using FetchXML queries for some complex requirements. Dynamics 365 WebAPI supports querying using “FetchXML”. With FetchXML, it can be easily generated using “Advanced Find”.

Advanced Find is a powerful feature in Dynamics 365 that can be used easily by literally any user without SQL query knowledge. It is specifically helpful when there is a need to narrow down results to the minimum, based on the ‘specified filter’ criteria.

You need to follow the below steps to general FetchXML queries using ‘Advanced Find’:

Step-1: Search and open “Advanced Find”

→ To access ‘Advanced Find’ in Dynamics 365, click on the ‘funnel’ icon in the upper right-hand corner.

Advanced Find

→ By clicking on the ‘funnel’ icon, the “Advanced Find” window will open.

Advanced Find funnel

→ In the Look for drop-down option, select an entity for which you want to generate a FetchXML Query.

Look for drop-down option

→ Click Select to define search criteria. Fill in the criteria. (You can select fields from the current record type, or from related records.)

Select to define search criteria

→ At the bottom of the “Select” list, the Related section shows related record types.

For example, most record types have a Related record type. To select fields from a related record type, select field, and a new Select link appears.

new Select link appears

Step-2: Specify the sort order

Follow the below steps to manage the order

→ Select Edit Columns to add/remove columns and edit the columns in the Query search results.

Edit Columns to add and remove columns

→ Select “Configure Sorting” to sort the columns and its view.

Select Configure Sorting

→ Specify the column to sort on, specify the sort order, and then select OK.

Configure sort order

→ After selecting the options for “Sort By” and “Then By”, select ‘OK’ to save the changes.

Step-3: Add additional columns to Advanced Find query

→ In the “Add Columns” window, you can click on the Add Columns to add additional columns to the Advanced Find query.

Advanced Find query

→ After selecting the columns from the list, click on the “OK” button to proceed further.

Step-4: Get ‘Results’

→ Once you have your Advanced Find query complete, in the Advanced Find window, you can click on the red exclamation point (Results) to run the query.

red exclamation point Results

→ By clicking on the “Results”, you will get the matched result records of the selected entity based on selected filters.

selected entity based on selected filters

Step-5: Download FetchXML

→ In the “Advanced Find” window, you can click on the Download to download the FetchXml query.

Download FetchXML

Downloaded query:

→ Once you download the fetch XML query, you can use it for WebAPI.

download the fetch XML query

All product and company names are trademarks™, registered® or copyright© trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Read Related Blogs About Dynamics CRM

Customization Limitations in PowerApps Portal and How to Overcome Them

Customization Limitations in PowerApps Portal and How to Overcome Them

3 Min
Dynamics 365 Portal: Types, Benefits, and More

Dynamics 365 Portal: Types, Benefits, and More

7 Min
Power Apps Portal: Features, Benefits, and Use Cases

Power Apps Portal: Features, Benefits, and Use Cases

5 Min
To Top