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

All column values cleared when using UpdateIf to update value of 1 column in collection

I am using a gallery that contains a collection of invoice lines (colInvoiceLinesNew). I have a + icon to add a new record after the last visible row, and a trash can icon to delete a selected row. Screenshot below.

 

flybrit_0-1615149730913.png

 

Clicking the + icon to add a new record works without issue. A new record appears with the default values and current records retain their values. The OnSelect code is:

 

Collect(colInvoiceLinesNew,{InvoiceID: "",LineNumber: ThisItem.LineNumber + 1,CostCenter: "TBD (TBD)",Account: "TBD (TBD)",WorkType: "TBD (TBD)",LineAmount:0})

 

However, when I click one of the trash can icons to delete the relevant row, all of the rows in the gallery below the one deleted reset to the default values instead of retaining what appears on the screen. Any rows above the one deleted retain their values. The OnSelect code is:

 

Set(LineNumberDel, ThisItem.LineNumber);
RemoveIf(colInvoiceLinesNew,LineNumber=LineNumberDel);
UpdateIf(colInvoiceLinesNew,LineNumber>LineNumberDel,{LineNumber: LineNumber-1})

 

It seems that the UpdateIf code is causing my issue, but I'm not sure how to resolve it. Any help is greatly appreciated.

 

 

 

2 REPLIES 2
v-xiaochen-msft
Community Support
Community Support

Hi @flybrit ,

 

According to your description, I did the test for you.

Unfortunately, I cannot reproduce your problem.

Your code works in my environment.

 

Please refer to the steps below:

1\ This is my test collection.

ClearCollect(colInvoiceLinesNew,{LineNumber:1,LineAmount:3},{LineNumber:2,LineAmount:2},{LineNumber:3,LineAmount:1},{LineNumber:4,LineAmount:3},{LineNumber:5,LineAmount:6},{LineNumber:6,LineAmount:5})

 

2\ Add a gallery control 

 

3\ Insert a trash Icon into gallery control and set its onselect property to:

Set(LineNumberDel,ThisItem.LineNumber);
RemoveIf(colInvoiceLinesNew,LineNumber = LineNumberDel);
UpdateIf(colInvoiceLinesNew,LineNumber> LineNumberDel,{LineNumber:LineNumber-1})

 

4\ The result is as follows:

AAA.gif

 

Please try to change the version of powerapps.

v-xiaochen-msft_0-1615168275661.png

 

You could also try to use my collection to do the same test to find out whether this phenomenon is caused by other reasons.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

flybrit
Regular Visitor

Thank you for your reply @v-xiaochen-msft. I updated the authoring version to 3.21031.41, but that didn't resolve the issue. I will recreate the screen from scratch and see if somehow that solves the issue.

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

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (51,773)