cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
roli_
Level: Powered On

Patch - Patch from comma separated list.

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Patch - Patch from comma separated list.

Hi @roli_,

 

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

 

Community Support Team _ Michael Shao
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

6 REPLIES 6
Power Apps Staff lesaltzm
Power Apps Staff

Re: Patch - Patch from comma separated list.

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?

Community Support Team
Community Support Team

Re: Patch - Patch from comma separated list.

Hi @roli_,

 

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 Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
roli_
Level: Powered On

Re: Patch - Patch from comma separated list.

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?

Community Support Team
Community Support Team

Re: Patch - Patch from comma separated list.

Hi @roli_,

 

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

 

Community Support Team _ Michael Shao
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

Community Support Team
Community Support Team

Re: Patch - Patch from comma separated list.

Hi @roli_,

 

Do you need any further help on this?

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
roli_
Level: Powered On

Re: Patch - Patch from comma separated list.

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

 

 

 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,111)