Environment variables in Dynamics 365 (Dataverse) are special solution components that serve as environment-specific configuration settings. They allow you to store a key (unique name) and a value (such as text, number, JSON, secret key, etc.) outside your app or flow, so it's easier to manage.
Instead of hardcoding parameters—like an API URL or numeric threshold—into your solution, you can define them once using environment variables. These variables can be referenced across apps, workflows, and Power Automate flows, enabling easy adjustments without editing your solution's code.
Why Use Environment Variables?
Environment variables are especially valuable when moving solutions across development, test, and production environments. Because they're part of the solution package, each environment can have its own values configured during solution import.
Simplified deployments: Avoid hard-coded URLs or credentials. When you move your solution to another environment, you can set different values for each variable based on that environment.
Centralized configuration: Store settings in one place, eliminate duplication, and ensure consistency across your apps and flows.
Reusable across components: A single environment variable can be used in canvas apps, model-driven apps, flows, and plugins. For instance, if multiple flows rely on the same API endpoint, define it once and reference it everywhere.
ALM and secrets support: You can securely store sensitive information—such as API keys—using the “Secret” data type as environment variables support ALM (Application Lifecycle Management). These variables are managed as solution assets and are compatible with source control and solution import/export processes.
Creating Environment Variables in Power Apps
You create environment variables within a Dataverse solution using the Power Apps maker portal. Follow these steps:
1. Open a solution: Sign in to Power Apps, go to Solutions, and select an existing solution or create a new one.
2. Create a new variable: To add a new variable, go to the top menu and select New, then choose Environment variable.
3. Define the variable: In the panel that appears:
a. Name: Provide a unique schema name.
b. Data Type: Choose from JSON, Text, (Yes/No) Options set, Decimal Number, Data Source, or Secret.
c. Default Value (optional): A fallback value used when no override is provided.
d. Current Value: The active value for the current environment (overrides the default value if set).
4. Click the Save button to create the variable.
Once created, the environment variable is stored in Dataverse. The key point is that you’ve now defined a parameter (like a URL or number) that other components can reference.
Practical Tips
1. Default vs. Current Value: If both values are set, the Current Value takes precedence. If only a Default Value is set, it will be used unless overridden. During export, you can clear values to prompt users to enter them on import.
2. Data Types: Choose a data type that matches your setting. Use text for URLs or IDs, two options for a yes/no flag, decimal or whole numbers for numeric thresholds, and JSON if you need a structured value. Use the Secret type for passwords or keys (the Current Value will be stored encrypted).
3. Security considerations: Only users with appropriate Dataverse permissions (typically included in the System Customizer role) can modify or access environment variables.
Conclusion
Environment variables provide a powerful yet beginner-friendly way to manage configuration settings in Dynamics 365 Sales solutions. They allow you to define key parameters once and reuse them across multiple components without hardcoding it.
This helps with smoother deployments, and better maintainability. For example, instead of editing your solution to change an API endpoint or update a business rule, you simply update the environment variable’s value.
Use environment variables to decouple configuration from logic, improve security, and maintain a clean separation between environments.