cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bosscon1
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

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

4 REPLIES 4

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.

Hello, I have similar problem and I tried to use your solution but I get an error.  

 

My SharePoint lists has column names from 1 to 52. I have a Text Box whose name is "WeekCount". When this name for instance equals to 3, I want to write someting on column name "3". I tried to use your code like that:

 

Patch(LeaveList; {ID: Value(CellID.Text)}; Switch(WeekCount.Text; "1"; {1: DayCount.Text}; "2"; {2: DayCount.Text})) 

 

But program doesn't accepts {1: DayCount.Text} part. It doesn't detect column name. 

 

Do you have any idea to fix it?

 

Edit: I find the problem. When column name is number, we have to use  apostrophe while writing it. Correct form of above code:

 

Patch(LeaveList; {ID: Value(CellID.Text)}; Switch(WeekCount.Text; "1"; {'1': DayCount.Text}; "2"; {'2': DayCount.Text})) 

 

Thank you for your solution, I save a lot of time with that.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

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