Canvas Apps UDFs - udfGetEnvironmentVariable
The Safest Way to Read Environment Variables - udfGetEnvironmentVariable (Canvas Apss UDF miniseries)
The Safest Way to Read Environment Variables - udfGetEnvironmentVariable (Canvas Apss UDF miniseries)
Problem: There is no good out-of-the-box method to get Environment Variables in Canvas Apps. In most cases, you will use Power Automate flow for easy retrieval, but you can also do it as a function (but it will require premium licensing).
Function:
udfGetEnvironmentVariable(SchemaName: Text): Text = IfError(Coalesce(LookUp('Environment Variable Values', 'Schema Name' = SchemaName, Value), LookUp('Environment Variable Definitions', 'Schema Name' = SchemaName, 'Default Value')), Blank())
Returns override if present, else default, else Blank().
Usage (App.OnStart): Set(BaseApiUrl, udfGetEnvironmentVariable("crd_BaseApiUrl"));
Before usage, ensure that Dataverse tables are connected to your application!
If you have multiple variables to be loaded or you are using them in multiple places, centralize them in one startup block - most preferably in App. Formulas as well!
Browse articles