mlauer

collect task attachments in list item and show all attachments in next task

Blog Post created by mlauer Moderator on Dec 3, 2014

The first time I worked with attachments in a workflow, I ask where are the attachments stored and how can I show all attachments in the following workflow tasks to give an approver the possibility to read the attachments.

 

I have attached an NINTEX 2013 example site workflow using NINTEX Forms 2013.

 

A prerequisite is the installation of the Get List Item Attachment in Base64 Custom Action from Vadim Tabakman (see http://www.vadimtabakman.com/nintex-workflow-get-list-item-attachment-in-base64-custom-action-happy-thanksgiving.aspx).

 

In the first Flexi Task you can add multiple attachments. The task IDs are stored in the workflow variable task_ids This attachments are stored in the task items of the Flexi Task.

If the Flexi Task is approved an item is created in a data list.

 

To copy the attachments from the task item(s) to the list item the following steps have to be executed in a loop for each task ID:

  1. Call web service Lists.asmx with method GetAttachmentCollection to get the URLs of all task item attachments. The resulting XML is stored in workflow variable attachments_xml
  2. Extract the URLs from XML and store them in a workflow collection variable attachment_coll by Query XML action.
  3. For each attachment URL the following steps are executed:
    1. Get the attachment from task item in base64 format an store it in workflow variable attachment_base64
    2. Get the filename from attachment URL by Regular Expression action
    3. Call web service Lists.asmx with method AddAttachmentCollection to add the attachment to the list item

 

 

Now all task attachment are stored in the list item.

 

To show the attachments formatted  as HTML links in the next Flexi task form the following steps have to be executed:

  1. Call web service Lists.asmx with method GetAttachmentCollection to get the URLs of all list item attachments. The resulting XML is stored in workflow variable attachments_xml
  2. Extract the URLs from XML and store them in a workflow collection variable attachment_coll by Query XML action.
  3. For each attachment URL the following steps are executed:
    1. Get the filename from attachment URL by Regular Expression action
    2. Build the html coding for the links and store it in the workflow variable attachment_html_links

 

Now the html coding for the attachment links is ready to be rendered in the form of the next flexi task.

 

To show the links in the form I used a Rich Text control. My first attempt to enter the worklfow variable by Insert Referenz to the control was unsuccesful - the html coding was shown, not the rendered link. So a little JavaScript was neccessary. First I assigned a unique CCS Class name Anlagen to the control. Second I created a Single Line Textbox control where I inserted by Insert Referenz my workflow variable containing the html coding. The control itself was made invisible on the form by css. By JQuery the html content of the control will be replaced by the content of my workflow variable:

NWF$(document).ready(function () {

    try {

          NWF$('.Anlagen').html(NWF$('#'+ anlagen_html).val());

    } catch (err) {

 

    }});

Now the attachment links will be rendered:

 

I hope it is helpfull for someone!

 

Manfred

Attachments

Outcomes