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 / Using Patch with Switc...
Power Apps
Answered

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

(0) ShareShare
ReportReport
Posted on by 19

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!

Categories:
I have the same question (0)
  • Verified answer
    ThatAPIGuy Profile Picture
    925 on at

    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.

  • Verified answer
    bosscon1 Profile Picture
    19 on at

    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!

  • ThatAPIGuy Profile Picture
    925 on at

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

  • AnnaDewitt Profile Picture
    30 on at

    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.

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

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 474

#1
Valantis Profile Picture

Valantis 474

#3
WarrenBelz Profile Picture

WarrenBelz 375 Most Valuable Professional

Last 30 days Overall leaderboard