How do we pass configuration settings to the virtual entity plugins?

By | April 27, 2021

When configuring a data source in the plugin registration tool, there is this note which implies that we should be able to supply configuration settings to the data provider plug-ins:

image

There are a few more details in the docs:

https://docs.microsoft.com/en-us/powerapps/maker/data-platform/create-edit-virtual-entities

image

Which is encouraging, but it’s still not clear how do we read those configuration settings in the plugin?

So, with some help from Andrew Butenko who did have a very handy code sample in his git repo, I figured I’d summarize how it seems to be working.

1. We need to add configuration columns to the data source table

Note: data source table is, also, a virtual table, though it’s not the same virtual table for which we are creating plugins. It’s the one that we are specifying when registering a new data provider in the plugin registration tool. On the screenshot below, you can see “Connection String” column added to that table:

image

I’ve also added that column to the form.

2. What we are doing above, we are defining data source metadata. What shows up in the Settings->Administration->Virtual Entity Data Sources are “instances” of that metadata (it’s tables vs rows… entities vs records…)

image

In case with ITA Crud Test data source, I can now configure connection string settings there:

image

3. Finally, here is how we can read that connection string from within the plugin

image

What’s that IEntityDataSourceRetrieverService? There is not a lot in the docs, but here is a link anyways:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.ientitydatasourceretrieverservice?view=dynamics-general-ce-9

Still, it works, and we can use RetrieveEntityDataSource method to retrieve the “instance” of the datasource. From which, as you can see on the screenshot above, I can read connection string settings.

There seem to be one additional twist to all of this. Even though the plugin is running under the “logged in” user account, that account does not have to be given access to the data source entity. RetrieveEntityDataSource will still work either way.

Which means a System Administrator could configure the data source, provide required connection string value and other “secure” configuration details, and none of those would have to be exposed to the regular users, yet virtual entity plugin will still keep working. Neat, isn’t it?

Have fun!

Leave a Reply

Your email address will not be published. Required fields are marked *