web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Setting OnStart Variab...
Power Apps
Answered

Setting OnStart Variable for User Role

(0) ShareShare
ReportReport
Posted on by 33

I have some code that is giving a blank value. however, if I use parts of the code in a text box, it shows correctly. What am I missing?

 

 

Set(
 currentUser,
 User().Email
);
Set(
 currentRole,
 LookUp(
 UserEdit,
 'Editor Email' = currentUser,
 Role.Value
 )
)

 

 

Categories:
I have the same question (0)
  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi, i think your Lookup is configured wrong:

    Lookup needs 2 Arguments Lookup(Datasource,Formula to evaluate right record)

    Your Formula has 3 Arguments.

    Also, Lookup returns the datatype "record" which means some kind of a dictionary. In fact, it will return the whole row from your datasource, in ehich the condition matches.

    One solution I can imagine is: 

    Set(
     currentRole,
     LookUp(
     UserEdit,
     'Editor Email' = currentUser
     ).value
    )
  • Feenix Profile Picture
    33 on at

    Hi, 

     

    Thanks for responding. copying and pasting your code returns an error, but...

     

    If I do this:

     

    Set(
     currentRole,
     LookUp(
     UserEdit,
     'Editor Email' = currentUser
     ).Role

     

     

    and change the text box to currentRole.Value, I get a blank response. 

     

    If I do this:

     

    Set(
     currentRole,
     LookUp(
     UserEdit,
     'Editor Email' = currentUser
     ).Role.Value

     

     

    and change the text box to currentRole, it gives a blank result. 

     

    Ultimately, I would like to set the users role when they open the app so that I can use it to dictate what they see without having to check their role multiple times. I feel like this would create multiple connections to the sharepoint list than what is needed.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    OK. Is it possible, to provide a screenshot or further details of the datasource named UserEdit? Please provide also de datatypes of the collumns.

    But is seems you make some progress. If the Lookup works, you only have to get the right values from the response.

    You can also debug the response of the lookup by creating a variable named currentRoleRecord:

    Set(
     currentRoleRecord,
     LookUp(
     UserEdit,
     'Editor Email' = currentUser
     )

    I would set this code to the OnSelect of a button, so you can easy trigger it. 

    After that, you can check the variables pane on the left and explore the global variable you just created. 

  • Feenix Profile Picture
    33 on at

    Im not sure what happened yesterday, but today the code below is working.

     

    Set(
     currentRole,
     LookUp(
     UserEdit,
     'Editor Email' = currentUser
     ).Role
    )

     

    While messing around with it this morning, I ran the "Run Onstart"  for the app and the value showed. I was thinking I did that yesterday but maybe not. Its working today. Thank you @Anonymous for the help with the .value I was missing from the end of the code.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Oh, nice to hear.

     

    Actually, adding a .value is a common practice you have to do sometimes in powerapps 😂 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,041

#2
11manish Profile Picture

11manish 676

#3
Valantis Profile Picture

Valantis 655

Last 30 days Overall leaderboard