“I know how to upload new attachment using the attachments control in PowerApps, but how do I recognise files that were removed?”
When you work with files in PowerApps, the easiest solution might be the attachments control taken from SharePoint forms. It’ll give you the possibility to display files, select files from local drive, upload, download, or delete them, all in a single control. Yet there’s one thing PowerApps won’t tell you – which attachment, which file was removed? The attachment either is in the control, or it isn’t. Removed file is not. How do you recognise such file then?
Files in the attachments control
There’s some similarity between the attachments control and a gallery. You input a collection with files, and it’ll show them, e.g. attachments from a SP item. If it’s in the edit mode, it’ll include also the attach / remove file buttons.
But when checking the files in the control, you’ll see it contains only the files that are currently “active”, not the removed ones.
Since the removed file information is already lost at this moment, you must get it somehow differently.
Store and compare the attachments
You have access to two pieces of information in this situation. The “original” files, the already uploaded attachments, and the “current” files in the attachments control. That’s all you need. Just compare them and keep the difference – the deleted files.
IMPORTANT: It’s the same function for both control properties, the OnRemoveFile and OnUndoRemoveFile.
Firstly, store the original files in a collection. My example is taking them from a SharePoint item attachments.
ClearCollect(
colAllAttachments,
LookUp(
ColumnsQueryList,
ID = 9
).Attachments
);
Secondly, compare it with the files currently in the attachments control. Remove from the original collection all files that still exist in the control. That way you’ll get a new collection with only the removed files.
ClearCollect(
colAttIdForFlow,
RemoveIf(
colAllAttachments,
Id in atc_itemAttachments.Attachments.Value
)
);
Now, with the removed files in a separate collection, the next steps are up to you, e.g. by deleting the files using Power Automate flow.
Summary
While PowerApps won’t tell you directly which files users removed from the attachment control, it’s something you can implement by yourself. Reload the attachments with changes in the control, and compare the initial bunch of files with the current ones. Remove the files that still exist in the control and you’ll get the difference, the files that users removed.