Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Exporting FetchXML files from MS Dynamics instead of using Advanced find

(0) ShareShare
ReportReport
Posted on by 25

Normally to download a FetchXML file in dynamics CRM, I would do the following : 

1. launch the instance 

2. click on advanced find

3. Look for the desired entity 

4. download the FetchXML file.

I am wondering if there is a way to automate this process using PowerShell?

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    Hi silasng,

    It is very glad that you now have been able to access the fetchXml.

    If you had encountered any other problem when trying to customize the output, please kindly mark any answer you find helpful to close the current thread;

    then create a new thread for the new question, I will reply to you in that thread, thanks.

    Regards,

    Clofly

  • silasng Profile Picture
    silasng 25 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    cloflyMao

    thanks again for this and I am so sorry for the late response. 

    So, I tried it and I was able to access the fetch XML piece. However, I am not able to retrieve all the fields. When I change the "-Fields" option to "*", it still returns the same number of fields which I would consider a default and nothing more. 

    Asides this issue, your approach works great and i am grateful for your help. 

    If you know of a way I can get the full number of fields, kindly let me know ... thanks. 

  • PhuocLV Profile Picture
    PhuocLV 347 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    why you don't use this managed solution: github.com/.../View-FetchXML

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    Hi ,

    Have you exported fetchxml file successfully?

    Regards,

    Clofly

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    Ok, I'm waiting for your feedback. :)

    Regards,

    Clofly

  • silasng Profile Picture
    silasng 25 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    cloflyMao

    thanks so much for reaching out with a response, this looks promising and i will be trying it out shortly. Will get back to you with what i find.

  • silasng Profile Picture
    silasng 25 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    Kokulan

    So, it is a lot easier and less complicated querying advanced find and downloading the FetchXml because, then, I can choose to download an entity with all the fields it has. I am working with exporting entities from one dynamics CRM instance and importing them with their data to a different instance. The entities I am working with are in hundreds and each having different fields. creating a FetchXML for each of these entities will be a complicated task, Hence, the reason I need to automate this process using a tool like PowerShell scripting. Besides, I will also need to know the fields contained in each entity to create a FetchXML for it. I will then use the FetchXml to export data for each entity before importing them to the desired destination instance.

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    Hi silasng,

    We can use following commands in PowerShell to download fetchxml of a specific view.

    In Dynamics, it uses an entity called "savedquery" to save definition and properties of views in system, and fetchxml is also a property of the entity.

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/savedquery

    01062.JPG

    1423.JPG

    Therefore, we can retrieve fetchxml property of savedquery entity, create a variable to store the query, then use New-Item command to create a xml file.

    Before running commands, make sure that you have connected to Dynamics, run command 1 to extract fetchxml of a specific view and check whether the result is what you want.

    Command 1:

    (Get-CrmRecords -EntityLogicalName savedquery -FilterAttribute name -FilterOperator "eq" -FilterValue "My Active Contacts" -Fields fetchxml).CrmRecords.fetchxml 

    Output:

    pastedimage1598410287399v2.png

    Command 2:

    If the output is correct, create a variable to save the result. (There is no output in this step.)

    $query = (Get-CrmRecords -EntityLogicalName savedquery -FilterAttribute name -FilterOperator "eq" -FilterValue "My Active Contacts" -Fields fetchxml).CrmRecords.fetchxml

    Command 3:

    Create a new file in disk C, the value is from the variable.

    New-Item -Path "c:\" -Name "My Active Contacts.xml" -ItemType "file" -Value $query

    Now, our fetchxml has been saved as a xml file in root directory of disk C.

    pastedimage1598410512775v3.png

    pastedimage1598410545123v4.png

    pastedimage1598410608771v5.png

    Regards,

    Clofly

  • Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: Exporting FetchXML files from MS Dynamics instead of using Advanced find

    Hi

    Downloading Fetch XML file from advance find window is designed for manual downloads.

    You might be able to automate the advance find query creation and downloading of file using a web driver like Selenium and possibly with some scripts in C# or other supported languages. However, why do you want to download the query from advance find using PowerShell, why not directly create the Fetch XML query in PowerShell?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans