Exploring custom virtual entity provider data source configuration

We were recently working on a custom virtual entity provider.
While going through the Microsoft documentation https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/virtual-entities/custom-ve-data-providers . We noticed that it’s a good starting point, but some pieces of the puzzle or missing or well hidden.

As I was reading the blogpost of Jason Lattimer https://jlattimer.blogspot.be/2017/12/creating-custom-virtual-entity-data.html which will get you up to speed real fast. I noticed that we bumped in to the exact same questions and obstacles, for example “I’m still wondering how you’d go about debugging with the Profiler with no steps (remember the TBD earlier?).” Well that makes both of us.

Another question we struggled with was, how to retrieve the configuration from the new data source we created during the registration? (which in the end is the goal of this entity…)

Getting data from the data source configuration

There is currently no example on how to do this in the documentation. But after reviewing what has been added to the Microsoft.Xrm.Sdk.Data Namespace https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/virtual-entities/api-considerations-ve
we came up with the following easy solution.

EntityMetadata dsConfig = service.GetEntityMetadata(context.PrimaryEntityName);
Entity dataConfiguration = service.Retrieve("<<YOUR_DATASOURCE_CONFIG_ENTITY>>", dsConfig.DataSourceId.Value, new ColumnSet("<<YOUR_DATASOURCE_CONFIG_ATTRIBUTE>>"));
string externalUrl =  dataConfiguration.GetAttributeValue<string>("<<YOUR_DATASOURCE_CONFIG_ATTRIBUTE>>");

This retrieves the data from the configuration record and used like any other entity in your plugin.

Wrapping it up

After creation of the data source configuration entity, you can add custom attributes for configuration that you can read using the code above.
This will help to keep the data source as flexible as possible and manage all of the parameters from the data source configuration entity.