Create solution’s setting file for export-import purposes (Power Automate + Dataverse)

When I published this blog post about Power Automate Deployment (manual), the great – Bill Blancett gave suggestions regarding the solution’s import setting file that we can use if we want to import the solution using CI/CD or using Power Platform Tools CLI (you need to make sure you install this on your machine):

Bill's suggestions to prepopulate connection reference/environment variables.

TL/DR from my blog post, when I import the solution using “pac solution import” command, the solution is imported successfully. But you will get an error because the connection references are not being defined. So, here is the tutorial regarding Pre-populate connection references and environment variables for automated deployments!

By my observation, here is what we gonna do:

Flow how to import solution with setting file

The concepts are very clear to me:

The environment variable can differ from 1 environment to another. When we define the default value and the current value, the solution will contain the information. So, when we import the solution without the solution’s setting file, the value will remain as it is.

Connection reference is different from the environment variable. Even though the solution for the demo contains the connection reference, you will not find any connection string or anything in the zip files (the export file).

Solution for today's demo

The connection reference will become a definition only:

Flow's connection will be reference from the connection reference

As you can see from the image above, the left-hand side is the connection reference’s definition (which doesn’t contain any information regarding the environment/user/password). While the right-hand side is the demo flow that I created. In the first couple of lines, it will show the connection reference selected.

Up until now, if you are importing manually using the command “pac solution import –path solution.zip” (you need to make sure you run the auth command first), the connection reference will be empty which leads to getting the error when the Flow is triggered (if you realize the connection reference name is different, it is because I changed it purposely in order to get the below screenshot):

Connection is empty.

While the environment variable will have the same values as the source environment:

Default value and current value is the same like the source environment.

So far, here is the conclusion:

  • Environment variable values (default value + current value) will still be the same as the source information.
  • Connection reference if we never import before (with the same name) will result as empty connection reference (like the above screenshot). But if you already imported the connection reference before + set the connection reference, it will not be empty.

Create solution’s setting file

Finally, we go to the steps to create the solution’s setting file. In my testing, you need to make sure the solution that you will use contains the environment variable/connection reference. If you don’t, when you run the below command will result in empty array values only (for EnvironmentVariables and ConnectionReferences properties). You only need to run the below command:

pac solution create-settings --solution-zip .\DemoFlow_managed.zip --settings-file .\DemoFlowTemmy2.json

It will generate a DemoFlowTemmy2.json file:

{
  "EnvironmentVariables": [
    {
      "SchemaName": "dev_DemoConnection",
      "Value": ""
    }
  ],
  "ConnectionReferences": [
    {
      "LogicalName": "dev_sharedcommondataserviceforapps_a4c3e",
      "ConnectionId": "",
      "ConnectorId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
    }
  ]
}

As you can see, we need to fill in the information for line number 5 and 11 with the value that we need for the Environment that we want to target. For the Environment variable (as usually is just a text) is much easier. You only need to update it using the value that you want:

{
  "EnvironmentVariables": [
    {
      "SchemaName": "dev_DemoConnection",
      "Value":  "{\"Message\":\"From Environment 2\"}"
    }
  ],
...
}

For the connection reference, you need to go to make.powerapps.com > select the environment that you want to add > Dataverse > Connections > you can create/select based on the connection type you need (for the demo, I’ll just use Dataverse connector):

Create a new dataverse connector

Once created, you can click the connection that you just created and you can see the below information:

Get the connectionid from the URL

You need to copy the connection id from the URL and paste it to the setting file JSON:

{
  "EnvironmentVariables": [
    {
      "SchemaName": "dev_DemoConnection",
      "Value":  "{\"Message\":\"From Environment 2\"}"
    }
  ],
  "ConnectionReferences": [
    {
      "LogicalName": "dev_sharedcommondataserviceforapps_a4c3e",
      "ConnectionId": "8a47cefd47104b129ff7a65f0ec05268",
      "ConnectorId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"
    }
  ]
}

Once done, you can save the file and you are ready to import using the below command:

pac solution import --path .\DemoFlow_managed.zip --settings-file .\DemoFlowTemmy2.json

Once finished, you can check again the environment variable and the connection reference value:

Result

Happy CRM-ing!

Author: temmyraharjo

Microsoft Dynamics 365 Technical Consultant, KL Power Platform User Community Leader, Student Forever, Test Driven Development, and Human Code enthusiast.

5 thoughts on “Create solution’s setting file for export-import purposes (Power Automate + Dataverse)”

  1. Hi Author,
    There’s an error when importing solution. It says couldn’t find conneciton XXXXXXXX for shared_commondataserviceforapps. But the connection is there in the target environment. Do you have any comments? Much appreciated!
    Randy

    Like

      1. thanks for your quick response. Which component should I add to the solution? In the solution, there’s only a couple of flows and connection references. We’re using pipeline to import the solution.

        Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.