cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BMarsh4
Frequent Visitor

Find Current User in SharePoint Online List

Hi,

 

Having some trouble achieving something at the moment; I've found a few very similar threads but nothing seems to work my side/hit exactly what I'm after.

 

I want to check, on load, whether the current user is a member of a list and depending on that result assign them a role.

 

I have a list called 'Admin' which is a simple one-column list containing a ~10 users; the datatype is Person/Group.

 

Currently I have the below in the OnStart section of my Form.

Set(currentUser, User())

 

A previous iteration also included UpdateContext({currentUser: User()}) but I can't see what, if any impact that is having on the logic.

 

I then have a Label with the text value of:

If(LookUp(Admin, currentUser.Email in User.Email),"Y","N")

 

I have also tried currentUser in User etc and also exposed the values in a gallery... If I apply the logic to the gallery it filters to show me the correct result but this doesn't help me in setting the value of a variable.

 

At this stage I just want to prove yes or no, is this user in this list but it returns blank regardless. Am I missing something very obvious here?

 

The next step would be to check that if the person is in the list assign them role X, if they're not, role Y.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @BMarsh4,

Do you want to check if the current user is within your Admin SP list?

Is the User a Person type column which does not enable "Allow multiple selections" option within your SP list?

Based on the formula that you provided, I think there is something wrong with it. The first argument of the If function is required to provide a Boolean value, but the result your LookUp formula returned is a Record value.

I have made a test on my side, please take a try with the following workaround:2.JPG

Set the OnVisible property of the first screen of my app to following:

Set(currentUser, User())

Set the Text property of the Label control to following:

If(!IsBlank(LookUp('20190122_case12', currentUser.Email in User.Email)), "Y", "N")

On your side, you should type the following:

If(
!IsBlank(LookUp(Admin, currentUser.Email in User.Email)),
"Y",
"N"
)

Above solution may cause a Delegation warning issue, in order to get rid of this issue, please take a try with the following workaround:

Set the OnVisible property of the first screen of your app to following:

ClearCollect(RecordsCollection, Admin)

Set the Text property of the Label control to following:

If(
!IsBlank(LookUp(RecordsCollection, currentUser.Email in User.Email)),
"Y",
"N"
)

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xida-msft
Community Support
Community Support

Hi @BMarsh4,

Do you want to check if the current user is within your Admin SP list?

Is the User a Person type column which does not enable "Allow multiple selections" option within your SP list?

Based on the formula that you provided, I think there is something wrong with it. The first argument of the If function is required to provide a Boolean value, but the result your LookUp formula returned is a Record value.

I have made a test on my side, please take a try with the following workaround:2.JPG

Set the OnVisible property of the first screen of my app to following:

Set(currentUser, User())

Set the Text property of the Label control to following:

If(!IsBlank(LookUp('20190122_case12', currentUser.Email in User.Email)), "Y", "N")

On your side, you should type the following:

If(
!IsBlank(LookUp(Admin, currentUser.Email in User.Email)),
"Y",
"N"
)

Above solution may cause a Delegation warning issue, in order to get rid of this issue, please take a try with the following workaround:

Set the OnVisible property of the first screen of your app to following:

ClearCollect(RecordsCollection, Admin)

Set the Text property of the Label control to following:

If(
!IsBlank(LookUp(RecordsCollection, currentUser.Email in User.Email)),
"Y",
"N"
)

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-xida-msft Thank you!

 

I knew it would be something minor; I was assuming that because I expected a true result from the LookUp, this would be passing a boolean but makes sense that some clarification is needed.

 

Much appreciated!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,761)