Copy and Update Form Attachments to a Document Library

  • 21 August 2017
  • 6 replies
  • 130 views

Badge +1

The Scenario

In short we have an application for which a new customer to turn on their water service needs to submit two attachments. One is proof of occupancy and the other is identification. When complete our utilities department wants to have these documents put into a document library so they can access them later when they get customer service calls or need to reference for security and so on. We want to copy those attachments to a list and then fill out some columns such as name, address, and the type of document, either proof of occupancy or ID.

My Current Thought Process.

Copying them was easy, used the Copy to SharePoint workflow action and it works perfect. I have the documents in the document library and storing results from that action gives me both URLs for each of the documents. I believe I can use these urls to update the items, correct? My next step would be to use the hidden column "FormData" for the two attachment controls. Each control is named separately so I know which control was used to upload the document and in turn which type of document each are.

My Difficulty

I am having difficulty pulling the XML Query on the FormData column. I am not sure what I need to query in the Output 1 section.

I understand from posts such as this one https://community.nintex.com/thread/2698 that I should see it in form variables; however, when using a number of methods in many other posts to see what is in FormData I don't ever see the form controls. I did however successfully pull a form variable out of my XML query. I wanted to just store the file names in form variables but I couldn't see how you could store that information in a variable, saw every single other column/control but not the attachment controls.

Appreciate any advice or assistance.

Thank you.


6 replies

Userlevel 6
Badge +13

Hi,

I wrote a blog post that should help with this.

Turning Attachments into working documents - Part Deux 

Although written for O365 it should still apply to on premise. Query the XML to identify the different controls and then pull out the file name of the attachment.

Hope this helps, if so mark as correct.

Thanks

Badge +1

Ryan

Thank you sir, I was actually following another post by you which was part one, linked below for others.

Turning attachments into working, controlled documents.

I was able to reference both of these and work through what I needed, I'll post what I ended up doing as I found some irregularities between the actions, but it works well. The issue for me was I guess my own. I had it all right and it didn't work with regard to the query XML action. I used {Current Item:FormData} for the source and then /FormVariables/CONTROLNAME for the XPath query but it didn't return anything. So I started down the path of trying to see what was in form data so I can make sure I am getting my query right instead of doing blind queries. I still never was able to return the FormData field so I can see everything that is in there, but it works now with the above information.

So again thank you and I'll post the resolution for others shortly.

Badge +1

Here is the solution that ended up working for me. Some spots that could be improved and open to suggestions but right now I'm working so like everyone else, moving on to the rest of the workflow not related to the question. happy.png Sincerest thanks to anyone who has or will add input here. Community interaction like this is what makes a product worth having.

Copy to SharePoint

First I used the "Copy to SharePoint" Action. Nothing special, I just selected the destination document library and it copies them, but I want to update them later and add metadata so I need some way to reference the documents. Important piece for me was the "Store results in" section, I stored the results in a collection variable colAttachmentURLs. This returns a collection, array, with all the absolute embedded URLs, sorta, get to that later, but it looks like this:

Note: For this action you may want to think about the "Overwrite Options" and how that may affect you if users upload documents with the same name. I will use the "rename new item" option. These means I can't rerun it or I will have duplicate documents, but I won't overwrite an old document. We run this once and done.

XML Query

I have two of these since I have two attachment controls on the form and want the file name associated with each. We do not allow multiple documents in each attachment control. Once is for Proof of Occupancy and the other is for ID. Only can upload one of each. This is done through form validation and means I don't have to loop through multiple attachments. This XML Query should look into the FormData column of the item, find the From Variables and then the control name. It returns perfectly just the file name of the file that is uploaded. In the example below the txtCustIDFileName will have just the file name, for example MyID.pdf.

XML Query

Note: I have two of these, the only difference on the other one is in Output 1 CustID is changed to ProofOccupancy which is the control name on the form for the control that allows the user to upload another single attachment for proof of occupancy.

For Each Loop

Next action is a For Each Loop, nothing special. We are going to loop through the two items returned from the Copy To SharePoint action.

  • Target collection: colAttachmentURLs
  • Store results in: txtCurrentItemURL
  • index: numCount

List Query - Get document ID from document library using the absolute URL.

First step inside the loop is to query the document library for a document matching my absolute URL from the Copy to SharePoint array colAttachmentURLs. With the ID I can then update the document's metadata. Yes you can update documents by absolute URL, but that didn't work for me and I know why, more on that later.

Condition Statement

I won't go into the details, but basically I want to know which control I am on since I want to update the metadata on each document to say whether the file is for ID or for Proof of Occupancy.

Update List Item

I have two of these, the only difference is the Document Type as mentioned in the condition statement. I am updating the document based on document ID. So I could do this using absolute URL; however, the absolute URL returned by the Copy to SharePoint action has spaces in it. The absolute URL of the document uses %20 instead. When I tried updating based on absolute URL it bombed out. So I did the list query above to get the ID and then did another list query by ID to return the URL and saw this. So two choices, either alter the absolute URL in the collection, very valid, and update by url, or just use the ID. I left it with ID.

That is pretty much it. Loop ends as expected. The only part I need to test is if someone tries to upload two documents with the same name. IE both controls have documents with the same name. Since things are handled in the same order I think this would be an easy fix, or assumption, that is next to test.

Here is the entire workflow.

Again comments and input welcome. always want to get better with Nintex as I've only been using it a few months.

Userlevel 6
Badge +13

Glad we were able to help you find your solution. My only suggestion would have been around future proofing. If there's a chance that the number of attachment controls could change in the future then you could have created a list with the names of these controls in and then queried that list and done a For Each to iterate through them each when querying the XML. This means if you did need to change add attachment controls in future you can just add them to the form and the list and not change the workflow. But that's just a future-proofing thought!

Badge +4

Thank you so much for the detailed solution with screenshots!!! This saved my bacon. I have a requirement to save up to six attachments and this worked seemlessly! I My next step is to add more steps to the workflow to delete the original attachments and replace them with hyperlinks to the URL of the copied location. Wish me luck! 

Badge

Were you able to find a way to replace the attachments with URL to the document library?

Reply