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

Using Patch with Switch to 'Pin' records to top based on User

Hello All,

 

I can find 99 Percent of my answers here in the forum without posting, so thank you all for that.  However, I'm a bit stumped. 

I'm trying to Pin favorite record values to the top of the Sharepoint List Gallery for easy access.  So, that part is not the problem.  The problem is that each User will have his/her own favorites, so I need to be able to store that information somewhere.  I'm using a checkbox to get a true/false from the user, and Patching the value to a Column unique to each user.  So, it all works when there is just one user, but when I use Switch to change the User_Favorite column name, the Patch isn't sucessful.  

 

This is the Patch Command for OnCheck

Patch(Vendors, First(Filter(Vendors, ID = ThisItem.ID)), Switch(
CurrentUser.Email,"user1@company.com",{User1_Favorite_Column: true},
CurrentUser.Email,"user2@company.com",{User2_Favorite_Column: true}))

CurrentUser in this scenario is OnStart=Set(CurrentUser, User()) so as to be able to use CurrentUser throughout the app to filter Records in a manner compliant with Sharepoint Delegation rules.  

 

The Designer will take the formula without any red squigglies, so I think the syntax is correct.  But it's not matching CurrentUser.Email with "user1@company.com".  I tried Capitalizing the first letter of the email in the quotes to no avail.  So is there another syntax for this that works?  Or is there another method to accomplish this that I am missing?  

 

Any help would be appreciated.  Thanks in advance!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Hi @bosscon1

 

CurrentUser.Email might be returning the email with some letters capitalized apart from just the first letter, so try this - 

 

Patch(Vendors, First(Filter(Vendors, ID = ThisItem.ID)), Switch(
Lower(CurrentUser.Email),"user1@company.com",{User1_Favorite_Column: true},
Lower(CurrentUser.Email),"user2@company.com",{User2_Favorite_Column: true}))

 

Also, just a suggestion, wouldn't you rather have just one column like User_Favorited_column and you just need to patch a "Yes" or true and then when you are displaying it on sharepoint , you just sort by the User_Favorited_column?

 

Hope this helps!

 

Let me know if you have any questions.


Vivek Bavishi aka That API Guy
PowerApps and Flow MVP
Blog | Twitter | YouTube | Community Profile | GitHub



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

You are awesome.  That did the trick.  I wouldn't have considered that capitalization would have been an issue.  

 

You asked why I am using different columns for each user... my need is for each app user to have his/her own favorites displayed in the app at the top of the gallery.  I thought at first that I could Patch the User to Multichoice Person column but that avenue seemed complicated.  Since my User base is small, it is simpler to have a seperate yes/no column.  I couldn't come up with any other way to store the true/false for each user.  Let me know if you have a better idea though...I'm sure my way is not the most efficient...

 

@ThatAPIGuythanks again!

View solution in original post

3 REPLIES 3
Super User
Super User

Hi @bosscon1

 

CurrentUser.Email might be returning the email with some letters capitalized apart from just the first letter, so try this - 

 

Patch(Vendors, First(Filter(Vendors, ID = ThisItem.ID)), Switch(
Lower(CurrentUser.Email),"user1@company.com",{User1_Favorite_Column: true},
Lower(CurrentUser.Email),"user2@company.com",{User2_Favorite_Column: true}))

 

Also, just a suggestion, wouldn't you rather have just one column like User_Favorited_column and you just need to patch a "Yes" or true and then when you are displaying it on sharepoint , you just sort by the User_Favorited_column?

 

Hope this helps!

 

Let me know if you have any questions.


Vivek Bavishi aka That API Guy
PowerApps and Flow MVP
Blog | Twitter | YouTube | Community Profile | GitHub



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

You are awesome.  That did the trick.  I wouldn't have considered that capitalization would have been an issue.  

 

You asked why I am using different columns for each user... my need is for each app user to have his/her own favorites displayed in the app at the top of the gallery.  I thought at first that I could Patch the User to Multichoice Person column but that avenue seemed complicated.  Since my User base is small, it is simpler to have a seperate yes/no column.  I couldn't come up with any other way to store the true/false for each user.  Let me know if you have a better idea though...I'm sure my way is not the most efficient...

 

@ThatAPIGuythanks again!

View solution in original post

@bosscon1

 

Glad that it worked!

 

I think you are right about the favorite column method that you are using.  There might be some way to optimize which we could figure out if you share some more details/screenshots of your app, if you would like to. 


Vivek Bavishi aka That API Guy
PowerApps and Flow MVP
Blog | Twitter | YouTube | Community Profile | GitHub



If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Users online (7,105)