I’ve received a task recently where I had to integrate data from Dynamics 365 (CRM system) to Business Central (Finance system). But before sending the data from Dynamics 365 to Business Central, I have a PowerApps application to do some manipulation on the data. The data then will be sent from Dynamics 365 to the PowerApps application and then after the manipulation, the data will be sent to Business Central. To achieve these objectives I used the Dynamics, Business Central and Common Data Service connectors with Logic Apps and Flow.
First of all, I needed to capture the data that has changed in Dynamics 365. To do so, I’m using the Dynamics 365 connector. This connector is available for both Logic Apps and Flow. In the picture below, you can see how I’m capturing created or updated records from one of the entities present in Dynamics 365.
With this connector, you have several others triggers and actions you can use to get and/or manipulate data from Dynamics 365 like capturing created, updated or deleted records as well querying records in any of the Dynamics 365 entities.
PowerApps and Common Data Services (CDS)
When it comes to the PowerApps, for those that don’t know, it’s a powerful and easy framework to create business applications quickly by leveraging among other things the Common Data Service. And that’s exactly what I did. Any application needs a place so we can store data, and using the CDS, gives me a lot of advantages like don’t having to be concerned where to store and maintain this data for example. The CDS data is stored together in your Office 365 subscription on the cloud. Dynamics 365 for example, also uses the CDS, so if we are thinking about PowerApps, we will probably want to use also the CDS. But have in mind that it can work with several other sources like databases and APIs.
Ok, now that I gave a little bit of explanation about PowerApps, what I wanted to do is to get some of the data I had from Dynamics 365 and store them in separate entities in the CDS. I wanted to use separate custom entities in CDS to not work directly with the Dynamics 365 entities, but remember that I said before that Dynamics 365 also uses the CDS, so it’s completely feasible for a PowerApps to access directly the data in the Dynamics 365 entities (just know what are you doing if you choose this approach).
To send data to custom entities in the CDS, I wanted to use the CDS Connector available in Logic Apps because I started doing my development in Logic Apps, and here is where things started to get strange. Let me explain myself, this connector in Logic apps is able to see all the entities in the standard CDS database created for an Office 365 subscription (including all Dynamics 365 entities), but there’s also a capability of creating separate CDS environments (which I was doing for not messing up the standard Dynamics 365 environment during my tests), and here is where the CDS connector in Logic Apps does not work. Here is the forum thread where I, Wagner Silveira that works with me and some other guys were sharing our experiences with this connector: https://social.msdn.microsoft.com/Forums/azure/en-US/fb218fe2-1f13-4d37-a9fc-ee700f0326ea/logic-app-connector-to-quotcommon-data-servicesquot-does-not-work?forum=azurelogicapps&prof=required.
In the picture below, it shows that I can’t see the CDS database from the additional environment that I created.
So, to check if the same behavior was happening in Flow, I give it a try.
As you can see above, I have the standard environment, which I can access normally in Logic Apps using the CDS connector, but the other two environments (Demo and Demo 3), are not accessible in there, but in Flow I can access all the environments with no problem as you can see below:
So now I have the CDS connector working fine in Flow, but not in Logic Apps where I wanted it to be. Since I wanted to consume the data from the custom entities in CDS in PowerApps, I used Flow temporarily to do the CDS work for me. Logic Apps would be calling Flow until I had time to figure this issue out (yes, I know it’s a Frankenstein, but you take what it is given to you).
After I have the data that I want in the Logic Apps/Flow, then I’m able to persist the data into custom entities in the Common Data Service (CDS) as you can see in the picture below:
And below you can see the PowerApps application that is reading data from these custom entities. Please be aware that this is a demo application and the design was made by an integration architect, so the look and feel is as good as it can be ;).
Besides the solution is working now, it was not a good design having Logic Apps calling Flow to overcome the issue with the CDS connector. After talking with some people at Microsoft, it was given me the direction to use the Dynamics 365 connector to call the additional CDS environments and it worked perfectly as you can see below:
So the final solution is using only Logic Apps as it was the idea since the beginning, but it could be built entirely on Flow also since it has the Dynamics 365 and Business Central connectors as well.
Once the data is manipulated in PowerApps it can be sent to Business Central. To do so, there’s the Business Central connector, that is still in preview, that has the capability of interacting with it.
I wanted to add records to the SalesDocuments and SalesDocumentsLines tables. After some tries and with the help of the API documentation of NAV (the on-premises solution for Business Central), I was able to figure it out which parameters I needed to pass. This connector, since it is still in preview needs some refinements and adjustments. I couldn’t find all the fields that I needed in the designer, and some fields showing up in the designer for record creation were read-only which made my life harder. If I can’t change a field when creating a record, don’t show that field right? I passed this information to Microsoft and hopefully, they will adjust this.
For example, for creating a new record for the SalesDocumentsLines table, I needed to provide the document number (header of the item), the document type and the line number. These properties don’t show up in the designer and I had to work only in the code view to add them. Some other fields like the sellToCustomerNumber in the picture below, are read-only and you can’t change them.
This connector works pretty much the same way that the Dynamics 365 and CDS connectors, and besides these issues that I found, you shouldn’t have many problems working with it, but in case you find issues, please refer to the NAV API documentation that it will give you clues about what you need to do and also use the Microsoft forums.
So, in this blog post, I wanted to show a little bit of my experience working with these business connectors that Microsoft provided to us to enable working with Dynamics 365, Business Central, PowerApps and the Common Data Service.
As you could see I faced some challenges and had to work a little bit harder to accomplish what I wanted, but gladly the channels to talk with Microsoft are much more open nowadays and the community also helps a lot.
I’ll be posting in a while about a little bit more of my experience with PowerApps, so keep in tune on my next posts.
See you guys around.