Wednesday 24 January 2018

Custom Data Provider for D365 Virtual entities

                

One of the differentiating features in Dynamics 365 9.0 is Virtual Entities, and these are driven by Virtual Entity Data Sources and Data Providers.
Virtual Entities acts as a facade to external data into the system as if the data were present in the CRM.
Currently Dynamics 365 9.0 provides 'OData V4' Web API as one of the data provider and  COSMOS DB Data Provider in the app source. Apart from these Dynamics 365 9.0 gives us the flexibility to create our own data provider using which we can invoke our own APIs.
Below is the step by step approach to create D365 Custom Data Provider
1.     Create an Assembly with Retrieve Multiple and Retrieve Plugins. (Sample code for creating this is shared in the end of this post)


2.     Register Assembly on the CRM Org using the 9.0 version of Plugin Registration Tool , for the below demonstration i have used 9.0.0.7 version of PRT



3.     Create a solution with a desired name and publisher, For the demonstration purpose i have given the name as 'POC'. This would be used in the further steps.



 4.     Open the Plugin Registration tool again. Navigate to 'Register' and click on the option ‘Register New Data Provider’ from the drop down.



5.   Fill the details as shown below, Choose the above created solution ( 'POC' in this case')  and choose the assembly u have created in the previous steps ( my assembly is 'POC.CustomDataProvider.dll'  and it has the definition for both Retrieve and Retrieve Multiple Plugins), Also select the 'Retrieve' and 'Retrieve Multiple' plugins from the corresponding drop downs.


 6.     Create a new Data Source Entity and click on create from the Data Source Entity field.



7. You would get an exception ( product issue) as below or The PRT could crash as well ( in that case just repeat the process). If it is Just an exception click ‘OK’. 

       8.   Click on Register, Once all  the details are filled.

9.      Go back to CRM and navigate to the previously created Solution ( ‘POC’ in this case).  You will find a new Entity with the name given in the Data Source ( 'POC Data Source' ) in the solution.
10.  In this step we will have to verify the newly created Data Source Entity and update if this Entity fields are populated with 'External Name'.
 a)By Default, CRM creates 2 fields ( ‘poc_name’ and ‘poc_datasourceid) and the  Entity Main form has only 'Name' field displayed on it. 
b)Customize this entity with the fields and the form in line with your requirement . I have created a Custom SQL Data Provider from,  So I have customized the Entity for Data Source accordingly. The customization involves creation of additional Fields and adding the fields on the Form like below. 
c)Make sure that the external names are populated for all the fields and for convenience sake give the schema names of the fields as 'External name' for all the fields.
d)'Publish all Customizations' in the solution
11. Navigate to Settings -> Administration and create a new Data Source  and choose the Data provider created in the above steps. You would be using in your Virtual entities.



12.  Navigate to the Solution and Create a new Entity with the check box checked for 'Virtual Entity' with the above created Data Source and map the Virtual Entity fields  'External names' with schema name of the Custom Data Source.



13.  Once Solution is Published, Go to Advance find and Retrieve your Virtual Entity, you should be able to see results.

       14. Click  here to get the sample code for creating the Plugin.

7 comments:

  1. Where is the retrieve part of the sample code ?

    ReplyDelete
  2. Thanks for the post. How did you resolve the 'Create data source entity' crashes. I have tried it a dozen times now and the PRT is still crashing.

    ReplyDelete
  3. In step 10 - what is the External Name?

    ReplyDelete
  4. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post. b2b email lists

    ReplyDelete
  5. Does it effect the database server ? If number of users in my organization are more and they are continuously trying to access the external data source by virtual entities. Does it effects my other systems using the same database?

    ReplyDelete