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 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:
- Button 1- Create collection
- Button 3- update Last row with value of 5
- last row is updated with 5
Actual Behaviour:
- Button 1-Create collection
- Button 3 - Update last row with value of 5
- First null value is updated with 5
- 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 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.