cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Patch creading duplicate record

Hello,
I'm having an issue with Patch() creating duplicate records in my collection. My goal is to update a few fields in a record within a collection and then Patch the collection to the database to update the fields in the database. The issue I'm running into is that Patch is creating a duplicate record in the collection. I have a gallery, where a user selects a record and can delete the record. The delete is a soft delete in that a field in the record contains an IsDeleted value. Here is the collection before modification:

1.png
Here I've selected the record I wish to delete and verfied that the selected record is correct by using a label to display the PK ID of the record.

2.png
Here is the orignal collection now showing a duplicate value:

3.png
Finally, here are the various permutations of Patch I've tried to make this successfully work:
Using Lookup:
Patch(PendingEquipmentRequestsCollection, Defaults(PendingEquipmentRequestsCollection),
LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
{IsDeleted: true, ModifiedDate: Now(), ModifiedBy:varCurrentUser.Email}
);
Using First/Filter:
Patch(PendingEquipmentRequestsCollection, Defaults(PendingEquipmentRequestsCollection),
First(Filter(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID)),
{IsDeleted: true, ModifiedDate: Now(), ModifiedBy:varCurrentUser.Email}
);
Here is the validation of the selected record displayed in the label box:
First(Filter(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID)).ID
If I don't include
Defaults(PendingEquipmentRequestsCollection),
Nothing happens at all, but when I include it, it duplicates. Any suggestions on what I'm doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
panand99
Impactful Individual
Impactful Individual

Hi @Anonymous 

 

- Using 'Defaults' in patch will create new record.

- If you want to edit the record then you should use record  to update. (like gallery.selected).

 

Patch(PendingEquipmentRequestsCollection, RECORDTOUPDATE,
LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
{IsDeleted: true, ModifiedDate: Now(), ModifiedBy:varCurrentUser.Email}
);

 

 

Please accept this solution if it`s fulfill yor requirement.

 

View solution in original post

1 REPLY 1
panand99
Impactful Individual
Impactful Individual

Hi @Anonymous 

 

- Using 'Defaults' in patch will create new record.

- If you want to edit the record then you should use record  to update. (like gallery.selected).

 

Patch(PendingEquipmentRequestsCollection, RECORDTOUPDATE,
LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
{IsDeleted: true, ModifiedDate: Now(), ModifiedBy:varCurrentUser.Email}
);

 

 

Please accept this solution if it`s fulfill yor requirement.

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,997)