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 / EditForm remove attach...
Power Apps
Unanswered

EditForm remove attachments

(0) ShareShare
ReportReport
Posted on by 599

I have a powerapp newform with SharePoint as the datasource. User can upload documents in NewForm which gets stored in document library successfully. Below is the code for the same.

 

NewForm Submit Button

 

Iantaylor2050_1-1700675033460.png

 

 

ForAll(
 DataCardValue11.Attachments As file,
 'UAT-UploadtoDocLib'.Run(
 {
 contentBytes: file.Value,
 name: file.Name
 },
 DataCardValue3.Text,
 DataCardValue15.Text
 )
 );

 

I tried the same in EditForm, where user can upload additional documents. Sample2 and Sample3 are the new docs attached in EditForm. If i delete Sample1.docx here in EditForm, it should get deleted from document library as well. May i know how to achieve this?

 

Iantaylor2050_3-1700675131743.png

 

 

 

Categories:
I have the same question (0)
  • Hassan_SZ_365 Profile Picture
    542 on at

    Hi @Iantaylor2050 ,

     

    Here is a high-level approach to achieve this:

    1. Maintain a collection of the original attachments when the form is opened. You can do this in the OnVisible property of the screen or OnEdit property of the form.

    2. Compare the original attachments collection to the current attachments in the DataCardValue11.Attachments. Identify which attachments have been removed by the user.

    3. Call a Power Automate flow to delete the removed attachments from the SharePoint document library.

    Here's how you can structure the code in PowerApps and Power Automate:

    PowerApps:

    1. When the form is opened for editing, save the original attachments list:

     

    ClearCollect(originalAttachments, DataCardValue11.Attachments);​

    On the save button or OnSuccess of the form, check for deletions and call the flow:

    ForAll(originalAttachments, 
     If(
     Not(file in DataCardValue11.Attachments), 
     'PowerAutomateFlowName'.Run(file.Name)
     )
    );

    Replace 'PowerAutomateFlowName' with the actual name of your flow.

     

    Power Automate:

    1. Create a flow triggered by PowerApps.
    2. Add a SharePoint 'Delete file' action.
    3. Use the identifier of the file or the file path from the PowerApps trigger data to specify which file to delete.

      Remember, this is a high-level solution, and the actual implementation will require you to manage permissions and handle edge cases appropriately

       

      Best Regards,

      Hassan Raza

       
       
       
  • Iantaylor2050 Profile Picture
    599 on at

    Hi @v-qiaqi-msft 

     

    I tried getting the deleted documents from attachment control using above code. However the code is not working properly.

     

    I need to send the deleted document name from attachments control to the flow. May i know how to achieve this?

     

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard