Home > Canvas Apps > Canvas App/Custom Page | Get the environment’s ‘Environment URL’

Canvas App/Custom Page | Get the environment’s ‘Environment URL’

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:

  • 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(
            CurrentAppUri,
            "/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‘.

🙂

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment