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

Notifications

Announcements

Community site session details

Community site session details

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

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
    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
    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
    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard