Latest Posts

Environment Variables in PowerApps and Power Automate


Environment Variables are very useful in both PowerApps and Power Automate, at the time of moving the application from one environment to another, e.g., from Dev => Test => UAT => Production. Everything in the app and flow remains the same except the connections, keys, or any other reference that you specify as part of the environment variable.

Environment Variable requirement scenario:

  • You are creating an application using canvas app and Power automate.
  • This application connects to several SharePoint Lists and libraries so obviously you have got database connection objects references in canvas app and in flows.
  • Now when you move from Dev environment to Test environment, you need to publish the solution as Managed solution and because of that, you can’t change the connection objects neither in the app nor in the power automate flows.
  • I know you can change the references at the time of moving to the Test environment but if there are large number of lists used, then the job becomes tedious.
  • Now in this case, if you have used Environment Variable then only at one place you need to change the variable value and it will change the reference everywhere in the application.

Note:

  • You need to create a solution for environment variable. You can’t create environment variable for stand alone Power App or Power Automate.
  • Environment variables require exactly same structure of the backend database tables or connections of both source and destination (Dev, Test, UAT, Prod all the environments basically).
  • When you move from one environment to another, you just need to update the Environment Variable values, the other application remains as is.
  • One environment variable can be used across different components. E.g., a variable storing SharePoint site / List URL can be utilized in both Canvas App and Power automate flow.
  • Environment variables is supported by Dev Ops tools to enable Continuous Integration and Continuous Delivery (CI/CD)
  • Currently (Dec 2022) SharePoint Online and SAP ERP are the only data sources supported in Environment Variables in canvas app. In future there might be upgradation and you see more data sources supported.
  • If the environment variable is changed within an environment, then it will not work directly. Either it will work if you are importing your solution again or you will have turn off and turn on the solution. Until then the application will keep using the old value.

How to create Environment Variable?

  • In PowerApps portal, go to the Solutions tab
  • Open your solution.
  • Click on New >> More >> Environment Variable.
  • New Environment Variable window will open. You need to specify below details here.
    • Display Name (Mandatory): Mention the display name of the environment variable.
    • Name (Mandatory): This is the unique name is used to reference the variable in code and formulas.
    • Description: Describe the Environment variable.
    • Data Type (Mandatory): Choose from these types.
      • Decimal number
      • Text,
      • JSON
      • Yes/No
      • Data source
      • Secret
    • Default Value: The default value is used when a current value isn't set for the environment.
    • Current Value: Override the default value by setting the current value for your environment. Remove this value if you don't want to use it in the next environment.

How to use Environment Variable?

There are 2 ways to use environment variable

1. Using Dataverse connector – (We need premium license to use Dataverse)

  • Open and edit your app from the solution
  • You need to add these two data sources.
    • Environment Variable Definitions
    • Environment Variable Values
  • Now you can use this formula to get the value of the environment variable.
  • Here, coe_EnvVarTest is the name of the environment variable.

LookUp(

'Environment Variable Values',

'Environment Variable Definition'.'Schema Name' = "coe_EnvVarTest",

Value

)

2. Using Power Automate (No need of premium license)

  • Go to your solution and from there create a Power Automate flow.
  • Create a power automate flow with powerapps trigger.
  • Choose the action - Respond to a PowerApp or flow as shown in the screenshot.
  • Select the Environment variable that you have created.
  • That’s it. Just two step flow.
  • Now, go to Power apps, and add power automate.
  • Select the flow that you have created in the above steps.
  • You can write this formula to get the value of the environment variable from flow.
    Set(VariableValue, EnvVariableFlow.Run().envariablevalue);
  • You cannot directly run this flow on a label text. You can write this code on a button OnSelect property and set a variable value and then you can use that variable in a label or textbox.

We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint