How to use AddAttachment Method to add a document as list item attachment

  • 4 June 2020
  • 4 replies
  • 211 views

Badge +1

I am trying to add a document within a library to a list Item using the AddAttachment web method inside the "Web Request" action. But the document is corrupted after added as attachment.

The workflow failes, if I use "[FileData]" as token. If I use "FileData" or "base64Binary", the workflow works ok, but the document is corrupted again. Is there another token or way to do that in Office 365?

 

Any help is appreciated.

 


4 replies

Userlevel 4
Badge +9

Usually I use REST requests to copy files (Call HTTP Web Service action).
For example, to copy attachements from item to another :


{Variable:Current Site URL}‌/_api/web/getfilebyserverrelativeurl(@v0)/copyto(strnewurl=@v1,boverwrite=true)?@v0='‎‏{Variable:Attachment URL}‌'&@v1='‎‏{Variable:List Relative URL}‌/Attachments/‎‏{Variable:List Item ID}‌/‎‏{Variable:Attachment File Name}‌'

After having featch the Request Digest to be able to do POST request, by calling :


{Variable:Current Site URL}‌/_api/contextinfo

and fetching the XML node : //*[local-name()='FormDigestValue']

Badge +1

Hi @allan,


thanks for your feedback. I already use "call http web service" action to copy list item attachments to a library, but I am not able to configure the action properly the other way around.


So could you please explain a little more detailled, how to use and configure the actions to add a document to a list item attachment?


Many thanks in advance.

Userlevel 4
Badge +9
In fact if you already managed to copy a list attachment to a doc lib, it is the same thing.
You just have to copy the file to /sites/YourSite/Lists/YourList/Attachments/YourItemID/YourFile
Badge +1

Hi allan,


thanks for your reply. I tried that earlier, but was unable to use this structure /sites/YourSite/Lists/YourList/Attachments/YourItemID/YourFile in O365. I was not able to copy a file to a list item, in the way I tried it. But maybe there was a fault in my request.


 


Anyway, I could resolve my issue by using Nintex Workflow Cloud - that was very easy and simple. 


 


But as soon as I have a bit more time, I will give a new try to your solution 🙂

Reply