Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 38 Β· Components and ALM

Environment Variables and Connection References

Make solutions portable: use environment variables for URLs and settings, and connection references for credentials, so one package works in Dev, Test and Prod.

The same app must behave differently in each environment: Dev points at a test SharePoint site, Prod at the real one. If you hard-code that address in a formula, you have to edit the app after every import, which defeats the point of a pipeline. Environment variables and connection references keep environment-specific values outside the app so the same managed solution runs everywhere.

Environment variables

An environment variable is a named setting stored in a solution. It has a definition (name, type, default value) and an optional current value that is local to one environment.

Create one: in the solution choose New, then More, then Environment variable. Set:

  • Display name and Name (with your publisher prefix, for example ct_SiteUrl).
  • Data type: Text, Number, Decimal number, JSON, Yes/No, Data source, or Secret (backed by Azure Key Vault).
  • Default value (travels with the solution).
  • Current value (stays in the environment; set at import time).

Where you can use them:

  • In Power Automate flows (as dynamic content from the Parameters).
  • In canvas apps by adding the Environment variable definitions table and a LookUp:
TEXT
LookUp('Environment Variable Values', 'Environment Variable Definition'.'Schema Name' = "ct_SiteUrl").Value

(A common simplification is to read the definition's default or current value through the Dataverse tables Environment Variable Definitions and Environment Variable Values; the value row wins if it exists.)

  • A Data source type variable can hold a SharePoint site and list, so a flow's SharePoint action reads from a different list in each environment without editing it.

Connection references

A connection reference is a solution component that points to a connection without containing credentials. A flow does not say "use Ada's SharePoint connection"; it says "use the connection reference Requests SharePoint". At import, you choose which connection in the target environment fulfils that reference.

Create one: New, More, Connection reference, pick the connector and an existing connection (or create one). Inside flows, choose the reference when adding an action.

Why it matters:

  • Importing prompts you to map references to connections, so no hand-editing of flows.
  • You can change a connection (for example when a person leaves) in one place instead of editing every flow.
  • Flows owned by service accounts can use references backed by service principal connections, so they do not break when a person's password changes.

Keep settings outside the app

Environment variable URLs, numbers, flags
Connection reference Who connects, mapped at import

Same package, different values per environment.

1 / 2

Resolving values: a stand-in

The rule is "current value, otherwise default". This stand-in resolves variables for three environments from one definition set.

JS Stand-in: resolve environment variables

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Note that ct_SendEmails is false in Dev by default, so testing cannot email real people. Choose defaults that are safe.

Connection mapping: a stand-in

JS Stand-in: map references to connections at import

Press Run (or Ctrl + Enter) to see the console output here.

No output.

After import: turn flows on

Cloud flows in a freshly imported solution are often off until a user or the pipeline turns them on. If connection references are mapped, the flows can be enabled; otherwise they stay off with an error on the connection. Remember this when a deployment "works" but nothing runs.

Secrets

An environment variable of type Secret stores a reference to an Azure Key Vault secret; the secret value never sits in the solution. It requires setting up the Key Vault and permission for Dataverse. Never put API keys in a Text variable, because anyone who can read the variable can read the key.

Good practices

  • Use environment variables for anything that differs per environment: URLs, list names, thresholds, feature flags, support emails.
  • Prefix names with your publisher prefix and keep a naming standard.
  • Never put business logic that changes in a variable-length JSON blob unless you document the schema.
  • Keep default values safe (do not send, do not delete).
  • List your variables and references in the release notes so the person who imports knows what to set.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. What does a connection reference avoid?

    Flows point to a reference, and at import you map it to the right connection.
  2. 2. Which value wins in an environment variable?

    The environment's current value overrides the default.
  3. 3. Where should an API key be stored?

    Secret variables reference Azure Key Vault; the key stays out of the solution.
  4. 4. Why might a freshly imported flow not run?

    Flows can arrive off, and an unmapped reference leaves them unable to run.

Summary

  • Environment variables hold per-environment settings; the current value overrides the default.
  • Connection references hold connections by name and are mapped at import.
  • Use Secret variables for sensitive values and choose safe defaults.
  • Check flows are on after import.

Next: Security Roles and Sharing