cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Delete record from collection not working where on Excel sheet it did

I all,

 

I have a problem to remove a record from a collection. I have this line of code:

Remove(collectionUsers; GalleryUsers.Selected)

 

It was working fine when the gallery had a Excel sheet as a data source. So the question is why is the remove statement not working on my collection? (I didn’t forget to change the items in the gallery from the Excel sheet to the collection, so that is not the problem).

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Helper III
Helper III

Re: Delete record from collection not working where on Excel sheet it did

Hi  @eka24  ,

 

I cheat… 😁

 

True either Patch or Collect don’t remove the record from the original table, so a ClearCollect will return the deleted records too. Furthermore I also found that collect doesn’t modify a record from the original table.

 

I added an extra column called Updated to both the original table and the collection. Default the values in this column are set to “No”. When I delete a column I mark it as “Deleted”. Likewise I mark records with “Inserted” or “Changed”.  When I save the collection to the Excel sheet these columns a written too.

 

I also do a ClearCollect to refresh the collection which includes the previously deleted records. But – and here is the cheating part – I also do a

RemoveIf(cUsers; Updated = "Deleted");;  
UpdateIf(cUsers;Updated <> "No";{Updated: "No"})

which makes that I get a new fresh collection to continue working.

 

So the Excel sheet itself has still the deleted records, which is good because the Excel sheet in its turn will be synchronized with an SQL database. Records marked as “Deleted” will be removed from the database on synchonization.

View solution in original post

8 REPLIES 8
Highlighted
Community Champion
Community Champion

Re: Delete record from collection not working where on Excel sheet it did

Remove(collectionUsers, ThisItem)

Highlighted
Helper III
Helper III

Re: Delete record from collection not working where on Excel sheet it did

Unfortunate Remove(collectionUsers, ThisItem) gives an error in my app. The reason must be that the delete button is not placed in the gallery itself, but on a topbar label outside the gallery. So ThisItem is probably not in the scope.

 

However I found a workaround: I mark the record as deleted with the Patch statement. Than I can deal with this once the collection is written back to the Excel sheet.

Highlighted
Helper III
Helper III

Re: Delete record from collection not working where on Excel sheet it did

It still doesn’t make sense to me that a line like:

Remove(collectionUsers; GalleryUsers.Selected)

doesn’t work for a collection. The same line is working when the data source is an Excel sheet instead.

 

For the time being a solved by modifying the code to this:

Patch(collectionUsers; GalleryUsers.Selected; {Updated: "Deleted"});;
RemoveIf(collectionUsers; Updated = "Deleted")

 

The documentation on the Remove statement says: “For collections, the entire record must match.” I am a newbe to Powerapps so can someone enlighten me what that means. I want to understand what is going on.

Highlighted
Community Champion
Community Champion

Re: Delete record from collection not working where on Excel sheet it did

@AGroegelich 

    I have gone through your issue and realised the following;

1. Putting the remove outside the Gallery removes the first item on the list of your Gallery. This mean that at any point in time you want to remove the first item. if this is not the case and you want to remove any specific record apart from the first, then placing the remove inside the Gallery is the best option

2. After testing both table and collection with remove button outside the Gallery, the record in the table was removed but that of the collection was not removed. this is exactly what you said.

3. The reason in my view is that, a collection is linked to a table so removing from the collection using does not affect the original source. It is only after patching or saving to the record that it affect the original table.

 

 

If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

 

 

 

Highlighted
Helper III
Helper III

Re: Delete record from collection not working where on Excel sheet it did

Hi @eka24,


3. The reason in my view is that, a collection is linked to a table so removing from the collection using does not affect the original source. It is only after patching or saving to the record that it affect the original table.

That makes sense. But I anxious to know why I cannot remove a record from a collection in the same way as with a table in Excel. Even more because my workarround is working.

Highlighted
Community Champion
Community Champion

Re: Delete record from collection not working where on Excel sheet it did

The removal is temporary. It does not affect that table. May be am not doing something right.

 

1. I created a collection

2. Using patch and removeif as you did, it removed the record as you said

3. But when i clearcollect the record reappears. this indicates that the removal did not affect the original table

4. Kindly check your datasource if it permanently removed the record

 

 

If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

Highlighted
Helper III
Helper III

Re: Delete record from collection not working where on Excel sheet it did

Hi  @eka24  ,

 

I cheat… 😁

 

True either Patch or Collect don’t remove the record from the original table, so a ClearCollect will return the deleted records too. Furthermore I also found that collect doesn’t modify a record from the original table.

 

I added an extra column called Updated to both the original table and the collection. Default the values in this column are set to “No”. When I delete a column I mark it as “Deleted”. Likewise I mark records with “Inserted” or “Changed”.  When I save the collection to the Excel sheet these columns a written too.

 

I also do a ClearCollect to refresh the collection which includes the previously deleted records. But – and here is the cheating part – I also do a

RemoveIf(cUsers; Updated = "Deleted");;  
UpdateIf(cUsers;Updated <> "No";{Updated: "No"})

which makes that I get a new fresh collection to continue working.

 

So the Excel sheet itself has still the deleted records, which is good because the Excel sheet in its turn will be synchronized with an SQL database. Records marked as “Deleted” will be removed from the database on synchonization.

View solution in original post

Highlighted
Community Champion
Community Champion

Re: Delete record from collection not working where on Excel sheet it did

So is your problem resolved, then mark as a solution

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (11,365)