cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kriggo15
Post Patron
Post Patron

Only patch fields when the value changes

I have a gallery that is used for editing data on database columns. There are 10 text inputs that may get updated for each record in the gallery and sometimes the gallery has upwards of 500 records in it. 

The issue is that the patching can take several minutes to finish due to the volume.

I'd like to only patch the input fields that the user has changed instead of every input field. Is this possible in a gallery? How would I recognize whether a field has changed?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hi @kriggo15 

 

The easiest way would be to patch the values on OnChange of the text input controls but this will make more too and fro calls to data source.

Expression: Patch(DataSource, LookUp(DataSource, ID = ThisItem.ID),{ColumnName:TextInput1.Text})

 

In case, you want to perform bulk update and match each of the 10 inputs, you will need to create 10 extra labels inside each item and hide those. Then you can build the expression by using If loop to check the latest value with hidden label and then patch. This will be a complex expression and might slow down the app.

Expression: Patch(DataSource, LookUp(DataSource, ID = ThisItem.ID),{If(TextInput1.Text = label1.Text, ColumnName:TextInput1.Text)...for all fields})

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

6 REPLIES 6
yashag2255
Dual Super User II
Dual Super User II

Hi @kriggo15 

 

The easiest way would be to patch the values on OnChange of the text input controls but this will make more too and fro calls to data source.

Expression: Patch(DataSource, LookUp(DataSource, ID = ThisItem.ID),{ColumnName:TextInput1.Text})

 

In case, you want to perform bulk update and match each of the 10 inputs, you will need to create 10 extra labels inside each item and hide those. Then you can build the expression by using If loop to check the latest value with hidden label and then patch. This will be a complex expression and might slow down the app.

Expression: Patch(DataSource, LookUp(DataSource, ID = ThisItem.ID),{If(TextInput1.Text = label1.Text, ColumnName:TextInput1.Text)...for all fields})

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

GarethPrisk
Super User II
Super User II

What is your current patch pattern?

Do you have a local collection that you're updating for each Text Input update, for the given row?

How are you tracking the changes?

Are users updating 500 rows before saving anything? Would it make more sense to patch iteratively?

 

Otherwise, a simple pattern is to collect the row into another collection and do an UpdateIf to keep it reconciled for each subsequent change, for the row. Then you can patch the collection back and have less rows, and more concise data. If you're patching to CDS, it will ignore blank fields and items which are identical in the source.

I do not recommend the second expression which @yashag2255 has given. As they even mentioned, this has the potential to be an extremely heavy call and will likely lock up the app even for a relatively small amount of changes. That could be improved using a With statement, to include the referenced record contextually, but is still a heavy call if you're processing hundreds of records.

It may be a complex solution but works best when applied in such cases.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

kriggo15
Post Patron
Post Patron

Thank you all for the quick responses. I'm going to try to add some additional context and answer some questions below.

@GarethPrisk  - I'm using a ForAll and UpdateIf directly back to the SQL source. Users are updating the fields then saving at the end of the process. Currently I'm writing each field back with something like If(IsBlank(TextInput4_11.Text), Blank(), TextInput4_11.Text)

@yashag2255  - Would you foresee the calls made by the OnChange property as something that would hinder performance? At which point is it actually "changing". Is it writing after I add/remove a character or when I click off the input box? 

yashag2255
Dual Super User II
Dual Super User II

@kriggo15 

 

The Onchange event is triggered when you click outside the text Input control. Since you are dealing with large data, it will be quick in making the changes as soon as any input is changed.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

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.

Top Solution Authors
Top Kudoed Authors
Users online (3,530)