cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Bug: patching/updating last row in collection

Background

I have a scenario where I have to rebuild a concatenated string. The string gets split using the Split method and I Capture the output in a single column collection. I then update the rows of the collection based on some combobox controls and have a button to Concat the table back into a string to then update the data source when complete(This method is driven by the system i'm integrating with so I need to do this string manipulation in order to update values in the source system).

 

Issue

I have found then when patching or Update a collection where the record is Last(collectionname) the behaviour isn't correct. If you are applying this logic to a single column collection where the row was originally an empty value then the patching the last(collectionname) will update the first empty row or special character rather than the last row of the collection. Even after applying a placeholder string using UpdateIf against the collection doesn't result in the behaviour changing.

 

Example:

To prove that this is not specific to data in my app, I created a blank canvas app. 3 buttons and a data table.

Picture of Example AppPicture of Example App

1.Button 1: ClearCollect the collection:

On Select code

ClearCollect(testtable,{text:""},{text:"1005"},{text:"100"},{text:""},{text:"1105"},{text:""},{text:""},{text:""},{text:""}

2. Button 2: Update Collection to fill null rows with placeholders(for my background scenario I don't need to do this but i'm just showing that it doesn't make a difference even though it should).

 

On Select code

 

UpdateIf(testtable,IsBlank(text)=true,{text:"a"})

3. Button 3: Update last row in collection

 

 

On Select code

 

Update(testtable,Last(testtable),{text:"5"})

Expected Behaviour:

 

  1. Button 1- Create collection
  2. Button 3- update Last row with value of 5
  3. last row is updated with 5

Actual Behaviour:

  1. Button 1-Create collection
  2. Button 3 - Update last row with value of 5
  3. First null value is updated with 5
    1. If you press button 3 again it will update the next null row instead of the last or the one it updated originally

First row populated with 5First row populated with 5

Same behaviour above can be replicated if you include button 2 between buttons 1 and 3. so it doesn't seem to matter if the collection has null values though somehow it knows they were null originally and the last() function no longer behaves as expected.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Bug: patching/updating last row in collection

Hi @Jt0 ,

Just an update -- the response from @McCall Saltzman as below:

Quick answer is that Patch affects the first record in the target table that matches the 2nd argument. In this case, First(collectiontable) is the same as Last(collectiontable). I’d suggest adding an index or some other way of uniquely identifying that record.


The response from @Hemanth Kumar as below:

Here as the table is a single column table and both the first and last values of the table are empty. The return of “Last(CollectionTable)” is an empty string. The call for Patch(…) will try to match the first empty string and patch that row with the provided value.  Having unique keys to identify which row you want to patch is the right way to do this in any production app. This issue is working as designed.


On your side, please consider add a unique key/column in your table to identify which row you want to update, then try your Patch function or UpdateIf function to execute the update operation, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
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

3 REPLIES 3
Highlighted
Community Support
Community Support

Re: Bug: patching/updating last row in collection

Hi @Jt0 ,

Based on the issue that you mentioned, I have made a test, and the issue is confirmed on my side.

 

I have made a test on my side, I think this issue may be related to the placeholders string value or blank value you provided for the text column in you testtable collection.

If the you provide a same placeholders string value (e.g. 'a') for the test column in your testtable collection, the Last() formula seems not to be able to recognize which row/record with 'a' value is the Last row.

 

I would post this issue to my product team, if the issue is solved, I would reply here.

 

Currently, as an alternative solution, you should provide a different placeholders string value for the test column in your testtable collection.

I have made a test on my side, please take a try with the following workaround as alternative solution:1.JPG

 

2.JPG

 

3.JPG

Set the OnSelect property of the "Init" button to following:

ClearCollect(testtable,{text:""},{text:"1005"},{text:"100"},{text:""},{text:"1105"},{text:""},{text:""},{text:""},{text:""})

Set the OnSelect property of the "Placeholders" button to following:

ForAll(
RenameColumns(testtable,"text","text1"),
If(
text1 = "",
Patch(testtable,First(Filter(testtable, text = text1)),{text: "Placeholder - "&CountRows(Filter(testtable, text=text1))})
)
)

Set the OnSelect property of the "LastRowUpdate" button to following:

Patch(testtable, Last(testtable), {text: "5"})

Please check the following GIF screenshot for more details:Test.gif

Note: Please set a different placeholder value the test colum in your testtable collection.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Community Support
Community Support

Re: Bug: patching/updating last row in collection

Hi @Jt0 ,

Just an update -- the response from @McCall Saltzman as below:

Quick answer is that Patch affects the first record in the target table that matches the 2nd argument. In this case, First(collectiontable) is the same as Last(collectiontable). I’d suggest adding an index or some other way of uniquely identifying that record.


The response from @Hemanth Kumar as below:

Here as the table is a single column table and both the first and last values of the table are empty. The return of “Last(CollectionTable)” is an empty string. The call for Patch(…) will try to match the first empty string and patch that row with the provided value.  Having unique keys to identify which row you want to patch is the right way to do this in any production app. This issue is working as designed.


On your side, please consider add a unique key/column in your table to identify which row you want to update, then try your Patch function or UpdateIf function to execute the update operation, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
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

Highlighted
Regular Visitor

Re: Bug: patching/updating last row in collection

Hey @v-xida-msft,

 

This rational makes sense. thanks for looking into this.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (7,336)