Forum Discussion
Getting Data via FetchXML from Dynamics
Hi, I'm trying to get data via FetchXML into PowerBI. I followed the steps described in Use FetchXML in Power BI with Dynamics 365 customer engagement | crm chart guy.
I tried to connect but I always get a message, that the connection ist not possible because the string contains invalid characters.
The generated URL is: https://xxxx.api.crm4.dynamics.com/api/data/v9.1/accounts?fetchXML=%3Cfetch+version%3D%221.0%22+output-format%3D%22xml-platform%22+mapping%3D%22logical%22+distinct%3D%22true%22%3E%0D%0A++%3Centity+name%3D%22account%22%3E%0D%0A++++%3Cattribute+name%3D%22name%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22address1_city%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22address1_postalcode%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22businesstypecode%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22statuscode%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22a24_firmentyp_opt%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22ownerid%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22accountnumber%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22a24_customerlifecyclecalc_opt%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22a24_br_groesse%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22primarycontactid%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22a24_letztereservierung%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22ifb_letztertermin%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22ifb_letztesseminar%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22a24_letztesseminar_dat%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22a24_letztertermin%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22accountid%22+%2F%3E%0D%0A++++%3Corder+descending%3D%22false%22+attribute%3D%22accountnumber%22+%2F%3E%0D%0A++++%3Cfilter+type%3D%22and%22%3E%0D%0A++++++%3Ccondition+attribute%3D%22statecode%22+operator%3D%22eq%22+value%3D%220%22+%2F%3E%0D%0A++++++%3Ccondition+attribute%3D%22a24_firmentyp_opt%22+operator%3D%22eq%22+value%3D%22602370001%22+%2F%3E%0D%0A++++%3C%2Ffilter%3E%0D%0A++++%3Clink-entity+name%3D%22systemuser%22+from%3D%22systemuserid%22+to%3D%22owninguser%22+link-type%3D%22inner%22+alias%3D%22ac%22%3E%0D%0A++++++%3Clink-entity+name%3D%22teammembership%22+from%3D%22systemuserid%22+to%3D%22systemuserid%22+visible%3D%22false%22+intersect%3D%22true%22%3E%0D%0A++++++++%3Clink-entity+name%3D%22team%22+from%3D%22teamid%22+to%3D%22teamid%22+alias%3D%22af%22%3E%0D%0A++++++++++%3Cfilter+type%3D%22and%22%3E%0D%0A++++++++++++%3Ccondition+attribute%3D%22a24_accountteamtype_opt%22+operator%3D%22in%22%3E%0D%0A++++++++++++++%3Cvalue%3E602370001%3C%2Fvalue%3E%0D%0A++++++++++++++%3Cvalue%3E602370007%3C%2Fvalue%3E%0D%0A++++++++++++%3C%2Fcondition%3E%0D%0A++++++++++%3C%2Ffilter%3E%0D%0A++++++++%3C%2Flink-entity%3E%0D%0A++++++%3C%2Flink-entity%3E%0D%0A++++%3C%2Flink-entity%3E%0D%0A++++%3Clink-entity+name%3D%22a24_account_owner_history%22+from%3D%22a24_account_owner_historyid%22+to%3D%22a24_current_owner_history_ref%22+visible%3D%22false%22+link-type%3D%22outer%22+alias%3D%22a_2771f6761a2b4868b8d7d758447e5d59%22%3E%0D%0A++++++%3Cattribute+name%3D%22createdon%22+%2F%3E%0D%0A++++%3C%2Flink-entity%3E%0D%0A++%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E
I changed the first part of the URL to publish here. Does anybody have any ideas?
Thanks a lot in advance, Lisi
5 Replies
- AnonymousNot applicable
HI Lisi - I would like understand why the standard D365 in Power BI cannot be used? Why do you need to use the FetchXML?
- LisiRegular Visitor
Hi Daryl, if I get the data the usual way I have to import all kinds of tables and lot's of data. FetchXML would give me the chance to import a smaller amount of data from more than one entity. It would be more like importing a view from sql Server. Or is there another way? Thanks, Lisi
- AnonymousNot applicable
Hi Lisi ,
Based on this document——How to handle Special Characters in Fetch XML | Microsoft Dynamics 365 CRM Tips and Tricks . Fetch XML is the easiest way to write complex queries to retrieve data by joining multiple entities.
We could use webutility.htmlencode(uiname) to handle such an error. For example:
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- AnonymousNot applicable
Hi Anonymous - the following "Fetch XML is the easiest way to write complex queries to retrieve data by joining multiple entities" may be true, but Power BI would prefer a Star Schema rather than One Big Table.
Lisi - I wondering do you need to separate the URL and Relative Path to get the FetchXML to work. Chris describe this in the Blog - Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code Chris Webb's BI Blog (crossjoin.co.uk)