
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:
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?