When working with Dynamics 365 Business Central using the Power Automate connector, when you sleect its actions and triggers you need to select the environment and the company name from a dropdown box:
This is quite noisy if you want to move your flows between environments, because you need to specify again the connections on every trigger and action. Unfortunateky there’s no documentation on how to use the Dynamics 365 Business Central connector dynamically.
One way to make your workflows portable is by using Solutions (this should be a mandatory best practice for me) and Environment variables. Environment variables enable the basic application lifecycle management (ALM) scenario of moving an applications between Power Platform environments.
In this scenario, the applications stay exactly the same except for a few key external application references (such as tables, connections, and keys) that are different between the source environment and the destination environment. Environment variables store the parameter keys and values, which then serve as input to various other application objects. Separating the parameters from the consuming objects allows you to change the values within the same environment or when you migrate solutions to other environments.
To use environment variables with the Dynamics 365 Business Central connector for Power Automate, you need to first create a Solution in your Dataverse environment (you can’t use/access environment variables in a flow which is not in a solution). When the solution is created, go into your solution and on the command bar, select New > More, and then select Environment variable:
Here I create two environment variables:
- D365BCEnvironmentName: contains the Dynamics 365 Business Central environment name
- D365BCCompanyName: contains the Dynamics 365 Business Central company ID
The D365BCEnvironmentName environment variable is defined as follows:
The D365BCCompanyName environment variable is defined as follows:
If you use environment variables, the company must be passed with its ID. If you use the name (like CRONUS IT) you will have an error at runtime.
When the environment variables are defined, you can create a flow in your solution and when using the Dynamics 365 Business Central connector, you can use environment variables to add the requested parameters, as in the following example:
You can select the environment variables by using Dynamic content on the specific field and here select Environment Variables:
Now you can execute your workflow. In my demo here, the workflow is triggered when I create a new customer in Dynamics 365 Business Central. Here is the execution:
As you can see, Dynamics 365 Business Central connection parameters are now dynamically passed from the environment variables.
Now you can export your solution to a new environment (from example from DEV to TEST and then to PROD) in a totally dynamic way.
You’re ready for ALM