Skip to main content
Post

#PowerPlatformTip 127: 'Special User-Informations in PowerApps Studio'

#PowerPlatformTip 127: 'Special User-Informations in PowerApps Studio'

TL;DR: Auto-switch to a test email in Power Apps Studio and the real User().Email in production via IsBlank(Host.Version).

💡 Challenge

While developing apps in Power Apps Studio, you often want to use test values, like a test email address, without risking that they end up in production.

✅ Solution

Check whether the app is running in Studio mode. If it is, use a test email for development; in production the app automatically switches to the real user’s email address.

🔧 How It’s Done

Detect Studio mode with IsBlank(Host.Version) and switch the email accordingly. Pick one of these placements.

Option A - in App.OnStart (use Set):

Set(fxIsStudioMode, IsBlank(Host.Version));
Set(
    fxUserEmail,
    If(
        fxIsStudioMode,
        "testaccount@company.com",
        User().Email
    )
);

Option B - as Named Formulas in App.Formulas (not OnStart):

fxIsStudioMode = IsBlank(Host.Version);
fxUserEmail =
    If(
        fxIsStudioMode,
        "testaccount@company.com",
        User().Email
    );

🔸 Named formulas live only in App.Formulas, are always evaluated automatically and stay up to date - but they can’t be placed in App.OnStart.

🔸 Inside App.OnStart use Set() for a global variable (or UpdateContext() for a screen-scoped one).

🔸 Either way you get the test email in Power Apps Studio and the real user email in the web or mobile player, with no manual changes. The check looks at where the app runs (Studio or player), not at the target environment: a test app that is opened in the player also uses the real user. If you need to switch by environment, use a value that you set when you deploy, such as an environment variable. The test address stays in the app code, so remove it before you share the app widely.

🎉 Result

No more test emails used by accident in the player, the switch is seamless and automatic. The test address itself stays in the app code until you remove it.

🌟 Key Advantages

🔸 Prevents accidental deployment of test data

🔸 Saves time by automating email assignment

🔸 Keeps the test address from being used in the player. It only swaps the email string: it doesn’t sign in a test account and doesn’t limit access to production data, so check permissions with a real test account and use separate test data for write tests.

Special thanks to Matthew Devaney for sharing this fantastic Power Apps tip!

🎥 Video Tutorial

🛠️ FAQ

1. How do I determine if my app is in Studio Mode? Check whether Host.Version is empty with IsBlank(Host.Version). It returns true in Power Apps Studio and false in the web or mobile player. (Avoid StartsWith(Host.Version, "PowerApps-Studio"), because Host.Version is blank in Studio.)

2. Can I apply this pattern to other test values? Yes, use the same logic to switch between development and production values for any parameter.

3. Where should I place these formulas in my app? Use Set() in App.OnStart (Option A) for a global variable, or define them as Named Formulas in App.Formulas (Option B). Named-formula syntax (name = expr;) can’t be placed in App.OnStart; for a screen-scoped value use UpdateContext().

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.