Skip to main content

Notifications

Community site session details

Community site session details

Session Id : EGUNnu5DMHVcfD4kkHVs7g
Power Apps - Building Power Apps
Answered

Get current value of environment variable in a canvas app (Dataverse for Teams)

Like (0) ShareShare
ReportReport
Posted on 7 Jul 2023 07:20:41 by 128

Hi! I'm new to Power Apps, and currently making a canvas app using Dataverse for Teams. I want to use environment variables to store information that needs to be changed when importing the app to another enviromnet, but I'm having trouble using LookUp() to access the current value of the environment. 

 

I've added the environment variable ('testVariable') to the solution in the Power Apps for Teams app, and added the connections to the two tables 'Environment Variable Definitions' and 'Environment Variable Values' in my app. 

StineN_0-1688712846450.png

StineN_1-1688712915488.png

 

My problem is that the values for 'Schema Name' in the two tables are different, so I can't get LookUp() to work. The value in the 'Environment Variable Valu es' table was added automatically, but it just seems to have and ID, and not the actual name of the variable like in the 'Environment Variable Definitions' table. 

I'm able to get the Default Value of the environment variable by using a LookUp() to the Definitions table, but I want to use the Current Value for this environment. 

StineN_2-1688712965116.png

 

StineN_3-1688713018548.png

Here's the code that works (default value):

LookUp(
'Environment Variable Definitions',
'Schema Name' = "cr896_testVariable"
).'Default Value'

StineN_4-1688713079704.png

 

And here is the code that doesn't work, because there is no value in the Values table that matches the variable name: 

LookUp(
'Environment Variable Values',
'Environment Variable Definitions'.'Schema Name' = "cr896_testVariable").Value

 

StineN_5-1688713203997.png

 

Can someone please help me understand how I can get the current value from the tables? Thank you. 

 

 

  • Verified answer
    EricRegnier Profile Picture
    8,714 Most Valuable Professional on 29 Jan 2024 at 11:03:08
    Re: Get current value of environment variable in a canvas app (Dataverse for Teams)

    Hi @StineN, to handle both cases in one expression 1) where there's a current value and 2) when there's no current value but just a default value:

    Coalesce(
     LookUp(
     'Environment Variable Values',
     'Environment Variable Definition'.'Schema Name' = "name",
     Value
     ),
     LookUp(
     'Environment Variable Definitions',
     'Schema Name' = "name",
     'Default Value'
     )
    );

    Tip! I put this as a Named Formula to centralize the logic so it can be reference in many places.
    Hope this helps!

  • StineN Profile Picture
    128 on 07 Jul 2023 at 08:31:40
    Re: Get current value of environment variable in a canvas app (Dataverse for Teams)

    Thank you for your reply. I did indeed get the current value using that formula, but it doesn't seem to be consistent in terms of which variable it looks up. It doesn't seem to work when I'm having several environment variables. 

     

    When I first tried the formula, it returned the current value of another variable in the same environment. When I deleted all of the values from my other environment variables, it indeed returned the current value of "testVariable". But when I added another variable called "testVariableName" and gave it the current value "Stine", it still returned the value of "testVariable" even if I changed the schema name in the formula to the new variable. Not sure how that's possible. 

     

    Any thoughts? Thanks again! 

  • v-hanytian-msft Profile Picture
    Microsoft Employee on 07 Jul 2023 at 07:53:43
    Re: Get current value of environment variable in a canvas app (Dataverse for Teams)

    Hi @StineN ,

     

    We Create the Environment Variable blow.

    vhanytianmsft_0-1688716414427.png

     

     

    The formula of Current Value:

    LookUp(

    'Environment Variable Values',

    " cr896_testVariable" in 'Environment Variable Definitions'.'Schema Name' ,

    Value)

    vhanytianmsft_1-1688716414430.png

     

     

    Hope this will help you,

     

    Best Regards,

    Tina

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,662 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading started