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 - Patch from com...
Power Apps
Answered

Patch - Patch from comma separated list.

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I'm adding a favorite function across my app.

 

My idea was to save and collect Favorites from a table with a "favoriteType" column and a "favoriteData" column. When saving a favorite function, quite a few values (like category, hour, duration) are saved into the the "favoriteData" column, e.g. as comma separated. As each type of favorites could need different number and names of values, I would rather not go down the path of creating a column for each of them (would be poor database design).

 

I found it easy enough to save data into a field, but struggles to find a way to patch it, as the patch function expects record values and not a text string.

 

Any idea how to accomplish this, or ideas how to make and use a generic settings table?

Categories:
I have the same question (0)
  • McCall Saltzman Profile Picture
    Microsoft Employee on at

    That is correct, patch is used to update a record in a table. If your data does not fit that format, then patch won't be very useful. What are the columns in the table you're trying to patch to?

  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    I think you have already checked the documentation of the patch() function?

    Patch() in PowerApps

     

    For example, if here you would like to save a new record for the favorites table, then the formula should be:

    Patch(Table, defaults(Table), {FavoriteData:"",FavoriteType:""})

    Note that the required field must be filled with the record part in patch() function.

     

    You may also take a look at the other function for records in the article below:

    Understand tables and records in PowerApps

     

    Regards,

    Michael

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks for replies.

     

    As per now, I'm only capturing a few "favorites", which in the end should end up in a few variables I could use in my patch function. But it could also be settings like language, theme etc.  Take look at the table below as an example.

     

    UserID SettingsTypeSettingsData
    1 ThemeLight
    1 LanguangeEng
    1 ExpFavoriteCode: 765, Amount: 876, Currency: GBP
    1ProjFavoriteProjID: 654456, Activity: 656, Hours: 10
    2ThemeDark
    3LanguageEng

     

     Theme and language would be easy to capture by filtering the table on UserID and SettingsType, but how to get data with several values splitted into variables (or in other ways get it into a patch function). I could possibly

    1. use a filter function to find the record
    2. split function to move data to a comma separated recordset
    3. use find and mid functions to get the data and pass it over to a variable

    Step one and 2 should be easy enough, but not sure how to do 3.

     

    Or other ideas? How do you guys capture user defined settings?

  • Verified answer
    v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    Let's take the following string as an example:

    Code: 765, Amount: 876, Currency: GBP

     

    Assuming you could find the ExpFavorite for the UserID 1, and now would like to pass the Amount Data into Amount1 Variable,

    To get the Amount value 876, we could take use of the following string:

    First(Split(Mid(SettingsDataField,Find("Amount",Label2.Text,1)+Len("Amount:")),",")).Result

    See example:

    19.PNG

     

    For the other part of the value, just switch the Amount with the related variable defined in your record.

    For example, if you would like to get value of Code, then use the following code:

    First(Split(Mid(Label2.Text,Find("Code",Label2.Text,1)+Len("Code:")),",")).Result

    Regards,

    Michael

     

  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    Do you need any further help on this?

     

    Regards,

    Michael

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Michael,

     

    Sorry for not replying before. I managed to find a way to do this myself, and forgot about my post.

     

    Your method seems to do it, but for reference, here is how I did it:

     

    First, get all data from the selected field into a variable:

    Set(ExpFavDataVar,ThisItem.SettingsData);

    Then, split the variable's data into other variables:

    Set(CodeVar, LookUp(Search(Split(ExpFavDataVar, ","),"Code:","Result"),1=1,Result));
    Set(CodeVar, Right(CodeVar,Len(CodeVar)-Find(":",CodeVar)));

    which sets CodeVar variable to "765".

     

    and repeat the same for all other values within the field, such as:

    Set(AmountVar, LookUp(Search(Split(ExpFavDataVar, ","),"Amount:","Result"),1=1,Result));
    Set(AmountVar, Right(AmountVar,Len(AmountVar)-Find(":",AmountVar)));

    which sets AmountVar variable to "876".

     

     

     

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 471

#2
WarrenBelz Profile Picture

WarrenBelz 395 Most Valuable Professional

#3
11manish Profile Picture

11manish 279

Last 30 days Overall leaderboard