Using environment variables in portals

Loading

Environment variables in Power Platform—including Power Pages—are a powerful way to manage configurations and settings that change between environments (e.g., development, test, production). Instead of hardcoding values like API keys, URLs, or feature flags into your Power Pages portal, environment variables allow you to centralize and manage these values flexibly and securely.

This guide walks you through the step-by-step process of using environment variables in Power Pages portals.


1. What Are Environment Variables?

Environment variables are reusable, configurable values used across different environments within Power Platform apps—including Power Apps, Power Automate, and Power Pages.

They support:

  • Consistent configuration management
  • Seamless app migration using Solutions
  • Separation of configuration from business logic

Common use cases:

  • External API URLs (dev vs prod)
  • Feature toggles (e.g., enable chat widget only in prod)
  • Secure tokens or keys (stored in Dataverse as secrets)
  • Reusable values for Liquid scripts and portal logic

2. Types of Environment Variables

TypeDescription
TextSingle string value
JSONStructured data in JSON format
SecretEncrypted and stored securely; only accessible via system logic
Data SourceConnectors or system-based data values

3. Creating Environment Variables

You can create environment variables via:

a) Power Apps Maker Portal

  1. Navigate to: https://make.powerapps.com
  2. Open your Solution or create a new one
  3. Click + New → More → Environment Variable
  4. Fill in:
    • Display Name
    • Name (used in code references)
    • Type (Text, JSON, Secret)
    • Default Value
  5. Save and publish

b) Portal Management App (Advanced)

If you need to directly reference or update via Dataverse, you can also create via:

  • Portal Management → Environment Variables

4. Referencing Environment Variables in Power Pages

Once created, you can access them in Liquid templates, JavaScript, or HTML within your portal.

Using Liquid to Access Variables

{% assign myVar = settings.my_env_variable_name %}
{{ myVar }}

Replace my_env_variable_name with the Schema Name of your environment variable.

Conditional Checks Example

{% assign featureFlag = settings.enable_feature_x %}
{% if featureFlag == 'true' %}
<div>New Feature Enabled</div>
{% endif %}

5. Using Environment Variables in JavaScript

You cannot directly access environment variables via client-side JavaScript due to security and backend context.

Workaround:

  • Use Liquid to output the value into the HTML/JavaScript
<script>
var apiUrl = "{{ settings.my_api_url }}";
console.log("API URL: ", apiUrl);
</script>

6. Securing Secrets

Environment variables marked as Secret are:

  • Encrypted at rest in Dataverse
  • Not accessible in Liquid or front-end code
  • Used mainly in server-side integrations, plugins, or Power Automate flows

Do not attempt to expose secrets in Power Pages front-end. Instead:

  • Use a secure backend (e.g., Power Automate with secure input/output)
  • Store non-sensitive configs in regular environment variables

7. Updating Environment Variables

To change a variable:

  1. Go to your Solution
  2. Open the Environment Variable
  3. Update the value
  4. Save and publish changes

Alternatively, use PowerShell, Dataverse API, or admin tools for scripted updates across environments.


8. Migrating with Solutions

Environment variables shine in ALM (Application Lifecycle Management):

  • When you export a solution with environment variables, the default values go along
  • When importing to another environment, you can override values during the import wizard

Example:

Dev API = https://api.dev.com
Prod API = https://api.prod.com

When you move the solution, just update the value—no need to edit the Liquid or portal code.

Leave a Reply

Your email address will not be published. Required fields are marked *