cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
calvares
Continued Contributor
Continued Contributor

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
shoog
Solution Specialist
Solution Specialist

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
Super User
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
Continued Contributor
Continued Contributor

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.

 

shoog
Solution Specialist
Solution Specialist

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

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.

shoog
Solution Specialist
Solution Specialist

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

calvares
Continued Contributor
Continued Contributor

Thank you both. That works well.

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,707)