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 / Patch SharePoint List ...
Power Apps
Answered

Patch SharePoint List with Lookup Values - Cannot update Lookup fields

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a SharePoint listing with a field called 'PowerAppUser' that is a lookup of 'people'

 

 I've run into two issues.  I'm trying to do a lookup of the currently logged in use to grab a default value for the app

 

Set(SelectedCommunity,LookUp(PowerAppUserPreferences,User().Email = PowerAppsUser.Email,DefaultCommunity))

This expression isn't throwing an error but it also isn't bringing back the value.  I'm not getting an error on the expression.  I've also tried reversing the condition and using the 'in' expression that didn't work either.

 

Along with that, I'm trying to update that record and I'm getting an error on my expression with regards to the PowerAppsUser field.  It is expecting a record rather than text.  I'm not sure how to build that expression

 

{PowerAppsUser:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:[where would I find the Id].ID,Value:User().FullName}}

Above is what I think I would use but I'm not sure what source I go against to find the 'ID' of a SharePoint user list - certainly it's not a value that is associated with my PowerUser user?  Also, what value should I be passing (Full Name, E-mail, etc.)?

 

Has anyone else tried this?  I searched the community and couldn't find an example.

 

Thanks!

Tom.

Categories:
  • Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    The User().Email function actually returns the UPN. For most tenants the email address is the UPN. However, there are tenants that use a different value for UPN then their email address. Just something you might want to check because it is being used in your lookup. What is the error you are getting when setting the SelectedCommunity variable?

     

    Setting the value for a person record looks something like this:

    PowerAppsUser:
    {'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Claims:Concatenate("i:0#.f|membership|",User().Email),
     DisplayName:User().FullName,
     Email:User().Email,
     Department:"",
     JobTitle:"",
     Picture:""
     }
    
    
  • Verified answer
    T.Grounds Profile Picture
    Microsoft Employee on at

    Thank you so much for the code!  I have been able to do what I needed to do.  

     

    Part 1:  Set the default in the dropdown for the 'Default Community' from the SharePoint listing looking up the user.  After much trial and error - I wasn't able to pull back any results using the .Email - but was able to pull back the record with the following statement:

     

    LookUp(PowerAppUserPreferences,User().FullName in PowerAppsUser.DisplayName,DefaultCommunity.Value)

    Part 2:  Update the value in the SharePoint Listing when the user changed the Community so that the next time they started the App, it defaults to the last used community (or if they never change the community, it defaults to the appropriate one for that user).  This code is in the OnChange action of the Community dropdown.  It first looks to see if a record already exists for the current user and if there is one, updates the 'DefaultCommunity' to the one they changed to.  If the system doesn't find the user, then it creates the record in the SharePoint list and sets the Default community value.  Here is the code:

     

    If(LookUp(PowerAppUserPreferences,User().FullName in PowerAppsUser.DisplayName,"Update") = "Update",
    
    Patch(PowerAppUserPreferences,First(Filter(PowerAppUserPreferences, PowerAppsUser.DisplayName =User().FullName)),
    {DefaultCommunity:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:'Cmb:SelectedCommunity'.Selected.ID,Value:'Cmb:SelectedCommunity'.Selected.Value}}),
    
    Patch(PowerAppUserPreferences,Defaults(PowerAppUserPreferences),{PowerAppsUser:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", Claims:Concatenate("i:0#.f|membership|",User().Email), DisplayName:User().FullName, Email:User().Email, Department:"", JobTitle:"", Picture:"" }},
    {DefaultCommunity:{'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",Id:'Cmb:SelectedCommunity'.Selected.ID,Value:'Cmb:SelectedCommunity'.Selected.Value}}))

    Thank you so much for the syntax!

     

    Tom.

  • simkessy Profile Picture
    72 on at

    What if you have multiple users and you need to patch more than 1 user to 1 record?

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard