cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
calvares
Impactful Individual
Impactful Individual

App Start Screen - no global variables

I'm trying to work out the new StartScreen property in App.

Previously my formula on App.OnStart was:

Set(loggedUserEmail,Office365Users.MyProfileV2().mail);
Set(varDPA, If(LookUp(Permissions, loggedUserEmail in Person.Email, true), true, false));

If(LookUp(ProjectRegister, loggedUserEmail = Author.Email || loggedUserClaims in IAO.Email, true), Navigate('Home Screen'), Navigate('Welcome Screen'))

I removed the last line of code from OnStart and added this to StartScreen:

If(LookUp(ProjectRegister, Or(loggedUserEmail = Author.Email, loggedUserEmail = IAO.Email), true), 'Home Screen', 'Welcome Screen')

However, I get the error message that global variables aren't allowed in the StartScreen property.

I see we have to use named formulas but what I tried didn't work. I guess I could replace loggedUserEmail with Office365Users.MyProfileV2().mail but then it would be querying it more than once.

My global variable loggedUserEmail is also used for looking up varDPA so it doesn't make sense not to use it again.

 

What is the best thing to do here?

 

1 ACCEPTED SOLUTION

Accepted Solutions

You could use the With function in stead of a global variable :

 

With({loggedUserEmail: Office365Users.MyProfileV2().mail},
If(LookUp(ProjectRegister, loggedUserEmail = Author.Email || loggedUserEmail = IAO.Email, true), 'Home Screen', 'Welcome Screen'))

 

 

View solution in original post

6 REPLIES 6
gabibalaban
Dual Super User
Dual Super User

@calvares ,

Please consult the StartScreen property detalied documentation. 

You cannot refer to global variables of the app inside this property even if they are defined in OnStart property of the same app.

Hope it helps !

calvares
Impactful Individual
Impactful Individual

Hi @gabibalaban 

Thank you for this.

So going by the documentation I would need to use the User() function to compare to the user in my data source.

 

The problem with this is that our User().Email function brings up a different email address in our business to the one saved in a people picker. I've found the only way to make the correct comparison and avoid a delegation warning is to use Office365Users.MyProfileV2().mail.

 

However I get a delegation warning when querying Office365Users in StartScreen using this formula:

calvares_0-1635783920634.png

I don't get a delegation warning if I use a similar formula but reference the variable in the OnStart:

calvares_2-1635784152944.png

 

I'd really like to avoid delegation altogether in this app, so any ideas of how to get around this issue would be appreciated.

 

You could use the With function in stead of a global variable :

 

With({loggedUserEmail: Office365Users.MyProfileV2().mail},
If(LookUp(ProjectRegister, loggedUserEmail = Author.Email || loggedUserEmail = IAO.Email, true), 'Home Screen', 'Welcome Screen'))

 

 

The @shoog solution works, with a small observation. As we talk about StartScreen property, the formula needs to return a screen name, not an action (like Navigate() ). So the formula you need is ... 

 

With(
   {loggedUserEmail: Office365Users.MyProfileV2().mail},
   If(
      LookUp(ProjectRegister, loggedUserEmail = Author.Email || loggedUserEmail = IAO.Email, true), 
     'Home Screen', 
     'Welcome Screen'
    )
)

 

Please accept @shoog 's reply as solution as it shows us the way to solve the issue.

Thanks for spotting that @gabibalaban , I forgot to change that part. Updated my post accordingly.

calvares
Impactful Individual
Impactful Individual

Thank you both. That works well.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,730)