In my previous article, I explained the steps to fetch the ‘Environment ID’ without the need of cloud flow.
In this article, lets see how to fetch the Environment URL using PowerFx formula. This works for both Canvas App and Custom Pages.

Steps to fetch the Environment URL:
- In your Canvas App, add following Data Sources

- On AppStart paste the following formula
// Fetch the 'Environment ID' of current environment
// Store the in the 'varCurrentEnvironmentID' variable
Set(
varCurrentAppUri,
First('Canvas Apps').AppOpenUri
);
Set(
varCurrentEnvironmentID,
Right(
Match(
varCurrentAppUri,
"/e/.*(?=/a)"
).FullMatch,
36
)
);
// Use PowerAppsforMakers.GetEnvironments() and fetch all the environments under the tenant
// Store Environments in to 'collAllEnvironments' collection
ClearCollect(
collAllEnvironments,
AddColumns(
Sort(
PowerAppsforMakers.GetEnvironments().value,
DataSourceInfo.DisplayName
),
"DisplayName",
properties.linkedEnvironmentMetadata.friendlyName,
"Url",
properties.linkedEnvironmentMetadata.instanceUrl
)
);
// Filter 'collAllEnvironments' with 'varCurrentEnvironmentID' and fetch the current environment's URL
Set(
varCurrentEnvironmentURL,
First(
Filter(
collAllEnvironments,
varCurrentEnvironmentID in id
)
).Url
);

- In the above formula, we are capturing the ‘Environment URL’ in to ‘varCurrentEnvironmentURL‘ variable.
- To display the ‘Environment URL’, Add a label and set the text property to ‘varCurrentEnvironmentURL‘.

🙂

![[Beginners] Power Fx: ShowColumns, AddColumns, RenameColumns and DropColumns](https://rajeevpentyala.com/wp-content/uploads/2024/04/record-ezgif.com-video-to-gif-converter-1-2.gif)
![[Step by Step] Configure and run 'Pipelines in Power Platform'](https://rajeevpentyala.com/wp-content/uploads/2024/08/image.png)
Leave a reply to Oob Cancel reply