“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.
Hi. This is helpful but I will need your idea and help on the attachment field and how it is being processed in Power Automate.
I have a Power Apps form that accepts multiple attachments. However, when updating the attachments, in Power Automate the Get changes from an item or file (properties only) returns a True or False if an attachment field has any values in it. Am I right?
The problems are like these scenarios:
-attachment is empty, user attaches 1 file = get changes action works
-attachment is not empty, user removes the only file = get changes action works
-other fields were updated along the attachment = get changes doesn’t work in a way that it doesn’t get the changes made for OTHER fields
-same when other fields were updated, and the attachment was removed = doesn’t recognize the changes made to other fields
Can you help me identify what is going on in these scenarios? I’ve done a lot of testing and inspecting but none worked.
Hi could you help me for copy attachment in power app?
I can set the attachment items=attachments from sp, but it’s not showed as “unsave”, and it’s not saved to sharepoint after submit form.