Hello everyone and welcome to my blog. In today’s blog, we will discuss how to reset a file attachment control in Power Apps
In this blog, I will use a fairly complex scenario. I will use a file attachment control outside of form control. If you are not aware of how to insert an attachment control outside of form control, checkout this blog.
The below screen has a file upload control. When I click on the ‘Clear Attachment Control‘ button, the files inside the attachment control should be reset.
In other words, clicking on the button should clear all the files in the file attachment control.
Apparently, it seems to be quite easy. There is a ubiquitous Reset function in Power Apps which should reset the control. Unfortunately the Reset function does not clear the attachments already selected.
Let’s look at the solution. We are going to use couple of properties of the File attachment control to achieve the desired solution. These are
- Items
- OnAddFile
First, I will work with the OnAddFile property. I am going to declare a collection and set it to the attachments collection of the File attachment control.
ClearCollect(
colAttachments,
fileControl_1.Attachments
)
The next step is to set the Items property of the control to the collection created in previous step.
The final step is to clear the collection on click of the Clear button. That’s it. Now let’s see all this in action.
Just to ensure that the Attachments property of the file control is reset as well, I added a Gallery control on the screen. I set the Items property of the Gallery control to Attachments property of the Gallery control.
Now let’s see the whole thing in action again, but this time with the Gallery control in place.
Wonderful isn’t it? What if I want to reset my file attachment control when I navigate across screens? It’s quite easy.
In the OnVisible of the screen where the attachment control is placed, we need to Clear the collection.
Below is the final behavior in action.
Hope this helped. You will also like the below posts.
Debajit Dutta
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.