web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Delete and overwrite a...
Power Apps
Unanswered

Delete and overwrite attachment not working when using Collections with AttachmentControl

(0) ShareShare
ReportReport
Posted on by 31

Hi, this may be a lengthy post but I have provided many details so that the scenario can be replicated and a discussion and experiments can be done by other users.

 

I have been doing some experiments with the Attachment Control. I have a basic SharePoint List (contains only Title field) and an integrated custom PowerApps form. For the custom form, I have added the AttachmentField and copied the Attachment Control twice into separate cards. It looks like this:

lancea1_0-1693383411240.png

 

The idea is to separate Vaccinations and Antigens by prefixing it with VAC or ANT respectively. For the most part, I have got it working when creating a new form and I have configured it this way:

 

App.OnStart

ClearCollect(VaccinationsCol, Defaults('PowerApps with Multi Attachments').Attachments);
ClearCollect(AntigensCol, Defaults('PowerApps with Multi Attachments').Attachments);
ClearCollect(AttachmentsCol, Defaults('PowerApps with Multi Attachments').Attachments)

 

VaccinationsAttachmentControl.Items

If(CountRows(VaccinationsCol) > 0, VaccinationsCol, Filter(ThisItem.Attachments,StartsWith(DisplayName,"VAC")))

VaccinationsAttachmentControl.OnAddFile

ClearCollect(VaccinationsCol,Self.Attachments);
UpdateIf(VaccinationsCol, !(First(Split(DisplayName, "-")).Value = "VAC"), { Name : "VAC-" & Name, DisplayName: "VAC-" & DisplayName });
ClearCollect(AttachmentsCol, VaccinationsAttachmentControl.Attachments);
Collect(AttachmentsCol, AntigensAttachmentControl.Attachments);

VaccinationsAttachmentControl.OnRemoveFile/OnUndoRemoveFile

ClearCollect(AttachmentsCol, VaccinationsAttachmentControl.Attachments);
Collect(AttachmentsCol, AntigensAttachmentControl.Attachments);

AntigensAttachmentControl.Items

If(CountRows(AntigensCol) > 0, AntigensCol, Filter(ThisItem.Attachments,StartsWith(DisplayName,"ANT")))

 AntigensAttachmentControl.OnAddFile

ClearCollect(AntigensCol,Self.Attachments);
UpdateIf(AntigensCol, !(First(Split(DisplayName, "-")).Value = "ANT"), { Name : "ANT-" & Name, DisplayName: "ANT-" & DisplayName });
ClearCollect(AttachmentsCol, VaccinationsAttachmentControl.Attachments);
Collect(AttachmentsCol, AntigensAttachmentControl.Attachments);

AntigensAttachmentControl.OnRemoveFile/OnUndoRemoveFile

ClearCollect(AttachmentsCol, VaccinationsAttachmentControl.Attachments);
Collect(AttachmentsCol, AntigensAttachmentControl.Attachments);

MainAttachmentControl.Items

If(CountRows(AttachmentsCol) > 0, AttachmentsCol, Parent.Default)

 

When creating a new form, items attached via the VaccinationsAttachmentControl will be prefixed with a "VAC-" while those uploaded via the AntigensAttachmentControl will be prefixed with a "ANT-". The attachments are always collected into the AttachmentsCol, which is used to fill-in the attachment contents of the MainAttachmentControl. The MainAttachmentControl is the one linked to the Attachments field.

 

I have no problems when I am uploading new files. The problem comes when trying to delete or overwrite an existing file. When you delete a file from the Vaccinations or Antigens attachment control, you can see that the collection will be deleted from the AttachmentsCol Collection. However, submitting the form will not make any changes to the existing attachments and the deleted file still remains. The same happens when trying to upload an existing file via the Vaccinations or Antigens attachment control. The form will be submitted but the changes will not be reflected.

 

The only time deletion or overwriting works is if it is done via the MainAttachmentControl, which is in the card linked to the Attachments field.

 

Is there any hidden function or property need to be set so that any deleted or overwritten files can be reflected between the different Attachment Controls?

Categories:
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 474

#1
Valantis Profile Picture

Valantis 474

#3
WarrenBelz Profile Picture

WarrenBelz 375 Most Valuable Professional

Last 30 days Overall leaderboard