web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Overwrite existing PDF...
Power Automate
Unanswered

Overwrite existing PDF attachment in SharePoint List

(0) ShareShare
ReportReport
Posted on by 13

Hi,

 

I have a Flow, triggered in PowerApps which creates a PDF file and adds it to the Attachments column in my SharePoint List and a Document Library. The problem I have is that I cannot get the Flow to overwrite the existing PDF in the Attachment column (if one has already been created). The PDF in the Document Library overwrites as I want it to.

 

See image of Flow below. 

 

Note that when using the 'Create file' action I can overwrite the existing PDF by setting 'Allow chunking' to off. This setting is not available for the 'Add attachment' action.

 

 

Flow.PNG

 

Add PDF file to SharePoint PDF's Library is the 'Create file' action.

The action Add PDF to SharePoint List ('Add attachment' action) is where the problem is occurring. 

 

Image of error below

 

Error.PNG

 

I have tried to update the Flow where it should delete the existing attachment but this did not work.

 

Any help appreciated. 

Categories:
I have the same question (0)
  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @ms123nw 

    there is no API to overwrite the list attachment, so you need to delete the attachment first before "updating" the content. Check out these two discussions from another forum:

    splistitem - Update attachment of list item using rest api is failing - SharePoint Stack Exchange

    sharepoint - REST API: How to create or update attachment in a list item? - Stack Overflow

     

    So the solution would be to use "SharePoint - Get attachments" action to check for the already attached documents, if the displayname is the same, delete the document and attach the new one.

     

    Hope this helps you.

     

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

  • ms123nw Profile Picture
    13 on at

    Hi @MarvinBangert,

     

    Thanks for the suggestion, I tried what you suggested plus some other things, but I still cannot delete the original PDF file in the way that I want to. The closest I've managed to get it to the behaviour I want is the following Flow (continued from the 1st image above ). 

    Flow2.PNG

    Note that the 'Get attachments' action will only run when 'Add PDF to SharePoint List' fails, it will fail when a file with the same name already exists. 

     

    The problem with this is that I've had to manually enter 'issue_51.pdf' as one of parameters for the Condition. This needs to be dynamic content so that it works with any PDF that might already be created. 

     

    If I select DisplayName from the action 'Add PDF to SharePoint List' (which is a 'Create attachment' action, just renamed) instead of manually entering a filename the condition evaluates to false meaning the 'Delete attachment' action will not run.

     

    I did change the condition to 'is not equal to' and the condition evaluates to true so the Delete attachment action runs, however this deletes every attachment for that particular list item and not just the PDF.

     

    Sorry for the long post, hope it makes sense.

     

    Any ideas?

     

    Thanks

     

  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @ms123nw 

    I builded this in my tenant, it's not completely the same as in your tenant, but maybe gives you an idea:

    MarvinBangert_0-1635975709411.png

     

    In my case I have a document within a SharePoint library and I trigger it on selecting this file. To get the content I need the "Get file content using path". Now is the part, which is helpful for you:

    Get attachments (from the SharePoint List), this will get all attachments first. Then I compare every Attachment DisplayName with the fileName (from the trigger, in your case from OneDrive). If there is an attachment with this name, delete it. After running through every attachment, I add the new attachment, so I can be sure, that the Attachment with this name has been deleted or never exists before.

     

    I hope this will give you a good idea on how to solve this!

     

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

    Blog: Cloudkumpel

  • ms123nw Profile Picture
    13 on at

    @MarvinBangert Thanks a lot for the image.

     

    This seems like its very close to what I need. The problem I now have is 'Add PDF to SharePoint List' does not run when a file with the same name already exists. Because this action doesn't run, any subsequent actions also do not run, meaning the attachment with the same name does not get deleted. To counter this I set 'Get attachments' to run after 'Add PDF to SharePoint List' has failed.

     

    The below image shows the error from the 'Delete attachment' action. 

     

    Error2.PNG

     

     

    The condition section of the flow is below

     

    Flow3.PNG

    The File identifier for 'Delete attachment' is coming from 'Add PDF to SharePoint List'. 

    I think the problem is because the 'Add PDF to SharePoint List' action doesn't run when a file with same name exists, the 'Delete attachment' action cant find a reference to the attachment ID and so it shows the attachmentId as null - Shown in image below

    attachment.PNG

    The flow runs correctly when an attachment with the same name does not exist.

     

    Any way around this?

     

    Appreciate the help

     

  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @ms123nw 

    you should try to think the flow the other way around, as in my picture within my last post, you can see the structure of the flow:

    1. Get attachments from a list item
    2. Apply to each (for each attachment from the get attachments)
    3. Condition to check, if the current item (attachment) name is the same as the document we want to add
      1. If Yes: Delete the existing attachment from the Item
      2. If No: Do nothing
    4. After the apply to each ran through all attachments and compared it with the new document, we want to attach, leave the loop and add the attachment. If there already was an attachment with the same name, it is deleted by the loop, if there was no attachment before, it will just be added.

     

    Does this help you? Otherwise please give me some more information.

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

    Blog: Cloudkumpel

  • ms123nw Profile Picture
    13 on at

    Hi @MarvinBangert, sorry for the delayed response.

     

    I've looked at my Flow and it follows the same structure as yours. See image below -

     

    Flow.PNG

    Image of the entire Flow is below -

    EntireFlow.PNG

    I think where the problem occurs is on the 'Add PDF to SharePoint List' (Add attachment action). Because there already exists an attachment with the same name, this action does not run, and so the following actions do not run either. I set 'Get attachments' to run after 'Add PDF to SharePoint List' has failed, even doing this I still can't get the desired behaviour. 

     

    The problem now is that 'Delete attachment' has a null value for 'attachmentId'. I believe this occurs because 'Add PDF to SharePoint List' does not run and doesn't create a value to be passed into 'Delete attachment'.

     

    The Flow does run correctly with newly created items. I can see that 'attachmentId' is not null for the new items. This is because 'Add PDF to SharePoint List' DOES run and a value exists to be passed into 'Delete attachment'.

     

    Thanks again.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard