Copy task attachments to list item attachments
Table of contents:
In this short post I will help you to build your Nintex for Office 365 workflow that will allow you to copy attachments that were added to a task to a related list item attachments. The list item is of course the one around which the whole workflow is running.
Approval task form
First you need to create an approval form.
It really doesn’t matter which type of a designer will you choose – each allows you to use Task attachments control (or in the modern designer – File upload control):
Configure the form the way you need it. After you’re done, get back to the approval action.
Approval action
Whether you use “Assign a task” or “Start a task process” action, you need to configure the field that returns task (or tasks) ID:
You will later use those IDs to get attachments from the related tasks (or task).
Workflow
First get the workflow a moment to wait after the approval is completed. I noticed, that sometimes workflow was resuming much faster than the attachments were uploaded to the task item. In result, workflow was resumed with information about e.g. just one attachments from 3 uploaded.
Then for each generated task do the following:
- Prepare headers for the HTTP request:
- Perform a GET HTTP request to the following request URL:
{SITE URL}/_api/lists/getbytitle('Workflow Tasks')/items(TASK ID FOR CURRENT LOOP RUN)/AttachmentFiles?$select=FileName,ServerRelativeUrl
- The response body will be of the following structure:
{"value": [{"FileName": "xyz.jpg", "ServerRelativeUrl": "somepath/xyz.jpg"}]}
– you need to extract the table only. - Then perform action for each item from the extracted table.
Next for each extracted attachment (in the loop iterate over the var_Data_dict dictionary and save item as eg. var_Item_dict):
- Get filename from the dictionary
- Get path from the dictionary
- Prepare request headers (like above, optionally you can add second item as
Content-Type: application/json
) - And perform the copy POST request to:
{Workflow Context:Current site URL}/_api/web/getfilebyserverrelativeurl(@v0)/copyto(strnewurl=@v1,boverwrite=true)?@v0='{Variable:var_Path_txt}'&@v1='/SITE RELATIVE URL TO LIST/Attachments/{Current Item:ID}/{Variable:var_Filename_txt}'
And that’s it! Task attachment is now added to the related list item’s attachments list. Good luck!
Telkom Jakarta
It’s great to see how Nintex Workflow for Office 365 can simplify tasks and make processes more efficient. The step-by-step instructions provided in the article make it easy to follow and implement. I appreciate the effort put into explaining the concept and providing detailed screenshots for better understanding. Looking forward to more articles like this!
Tomasz Poszytek
Thank you 😉
Ahmad Maza
Hello Mr.Tomasz,
I hope this message finds you well. I’ve been following your blog and the insights you provide on Nintex have been incredibly helpful. Currently, I’m exploring the capabilities of Power Apps and Power Automate, and I’m interested in creating a custom task form and send link via email for the custom form.
I noticed your expertise in Nintex, but I wonder if you have insights or resources on achieving a similar functionality using Power Apps and Power Automate exclusively. If you have any articles, tutorials, or advice on this specific topic, I would greatly appreciate your guidance.
Thank you in advance for your time and expertise!
Best regards,
Tomasz Poszytek
Thank you Sir! I can recommend you the Youtube playlist I have done exclusively around custom scenarios in Power Platform approvals: https://www.youtube.com/watch?v=45f8mRAiNjo&list=PLaHN-sDizNyWt1_qajlDZsFOU-A68ZVe0&ab_channel=TomaszPoszytek.
Gregor
HI Thank you, i can’t figure it out. i receive always “Specified value is not supported for the serverRelativePath parameter”
I use the relative path get by the response you mentioned. “ServerRelativeUrl”: “somepath/xyz.jpg”
regards
greg
Tomasz Poszytek
Be sure the path is relative down to site collection level, e.g. /sites/somepath etc…