Retrieve EnvironmentVariableValue in Power Fx

Benjamain JohnDyn365CE1 year ago17 Views

In my private project (Key Box), I stored a JSON configuration in an Environment Variable. To retrieve its value, I use two queries. The first query to retrieve the GUID of the Environment Variable Definition and the second query to retrieve the Environment Variable Value. I don’t use the Retrieve EnvironmentVariableValue function because I also need to update the environment variable later.

Power Fx to query an EnvironmentVariable and its EnvironmentVariableValue

1. Get the environment variable definition record by schema name

Set(
    envVarDefRec; 
    First(
        Filter(
            'Environment Variable Definitions';
            'Schema Name' = "new_YourSchemaName"
        )
    )
);;

Set(name; value) to create the variable envVarDefRec and store the value.
First(table) to get the first record of the passed table.
Filter(table; condition) to filter the Environment Variable Definitions table by scheme name.

2. Get the EnvironmentVariableValue record

Set(
    envVarValRec; 
    First(
        envVarDefRec.'Environment Variable Values'
    )
);;

Set(name; value) to create the variable envVarValRec and store the value.
First(table) to get the first record of the passed table.

3. Get the value from the EnvironmentVariableValue record

Set(name; value) to create the variable envVarVal and store the value of envVarValRec.Value.

Set(envVarVal; envVarValRec.Value);;

Bonus: Apply the default value from EnvironmentVariableDefinition record if the EnvironmentVariableValue is empty.

If(condition; then) to do the next action only if the condition is fulfilled.
IsBlank(value) to check is envVarVal contains data.
Set(name; value) to fill the variable envVarVal and store the value of envVarValRec.Value.

If(
    IsBlank(envVarVal);
    Set(envVarVal;envVarDefRec.'Default Value')
);;

Original Post https://benjaminjohn.de/retrieve-environmentvariablevalue-in-power-fx

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...