I have a form that allows users to upload attachments. I can add the attachments to a SharePoint Online list via a workflow and the SP Add Attachments to List action.
I need to Assign Task to individuals where they must review the list item attachments and approve or reject them.
I can easily add the actual Attachments to an email or Task notification via the form’s File Upload (Collection). However, I don’t see much sense in sending attachments via email, especially since they already exist in the SP online list. I would rather send the Task notification email with links to the attachments instead.
Unfortunately I have not found a simple way of doing that. The SharePoint Get Attachments action only works if the attachments existed in the list prior to starting the workflow. I seem to be unable to add the attachments during the workflow, then get their names and/or URLs, even if I re-query the list after the attachments were added.
Anyway, it occurred to me that I don’t need to actually get the attachment URLs from the list. I can build it if I just know the names of the attachments. The format for the attachment URL is:
https://SharePointSiteURL/Lists/ListName/Attachments/ItemID/AttachmentName
So I can build the attachment URL if I know the Site URL, List Name, Item ID, and the Attachment Name.
So, I set out to do just that in a Nintex Workflow Cloud Workflow that uses a start Form.
I created the form (see attached pdf file)
The form for my Proof of Concept Test is very simple. Just a “Data Lookup” control to a SharePoint list and a “File Upload” control. The list just has a Title field and accepts attachments.
The workflow (see same attached pdf file)
The workflow is rather simple as well.
- Start Event is a Form (described above)
- I query the SharePoint Online List, then set variables for List Item ID, and List Item URL.
- I then created an Action Set to iterate through the File Upload collection, add the attachments to the SharePoint Online List, and extract the attachment name and add it to a text variable.
- In the Action Set, I use the “Create a text string” action and save it as a text string variable.
- The trick is that the Text String is an HTML <table> with <div> and <a href> tags so that I can build the URL path to the list item attachment.
example: <table> - I then use “Loop for each” action to iterate through the “File Upload” Collection containing the attachments added to the form.
- Inside the Loop, I use the SharePoint Online “Add Attachment to an item” action
- Then I add the name of the current attachment
example:
<div><a href=https://SharePointSiteURL/Lists/ListName/Attachments/psItemID]]/oiAttachment name]]>AtAttachment name]]</a></div>
and then save the string variable back to itself. - Repeat steps 7 & 8 until there are no more attachments to add to the SP List.
- Once the loop is complete, I close the text sting variable (html table).
example: </table> - I can then send an email with the text string variable embedded in it, providing a list of attachment names with clickable links to the attachment in the SharePoint List.
All of this works fine. I can add the attachments in the form, get the correct list item ID, add the attachments to the correct SP List item, and even build a valid URL to the attachments, and send an email with the clickable links to the list item attachments. The email works. It contains valid links to the list item attachments.
The workflow however fails when it reaches an “Assign a Task” or “Assign a task to multiple users” action. I get the following error message:
The workflow has failed unexpectedly. oError Code: Runtime.Internal]
Any idea what is causing the “Assign a Task” actions to Fail?
See the attached pdf file for some screen shots of the form and the workflow.
Thanks