cancel
Showing results for 
Search instead for 
Did you mean: 

Generate a Word Doc with Images & Captions from Form Attachments (2013 pre-3.2.4.0)

rhia
Nintex Newbie
28 15 6,720

PLEASE NOTE: This advice is for those of you who are using On-Prem SharePoint 2013 prior to release 3.2.4.0. It's way easier in 3.2.4.0 as you have the image URL variable!

~~~

Only recently have I started using the "Document Generation" action instead of "Update Word Document" action.

I didn't realize what I had been missing out on. Suddenly, we can insert tables and images easily, as long as we have our populated variables and templates set-up correctly. And the photos can be auto-resized! AND CAPTIONED! Craziness. This is going to save coworkers a LOT of time!

I've taken care of the latter part (the template) for you, and it's attached to this post. The rest of this blog will teach you how to put it into use!

Let's focus on the idea of having an inspector out in the field, taking photos, and writing captions using a repeating section, all via Nintex Mobile - maybe on an iPad. I'll walk you through how we bring those pieces together, and if you need more detail on anything, there's a "further reading" section at the bottom.

Things of Note: 

  • Doc Gen allows 10 images per docx template
  • Doc Gen is subscription based - if you are on prem you may need to have it activated; if you are on O365 it should be there (I believe with 50 trial Doc Gens but I am not sure)
  • Resizing images requires placeholders - which is why this is offered in a template
  • This article will not cover how to build the images & captions template itself - but - that will be in a future post!
  • This article will also not cover how to deal with an unknown amount of pages - but - also, another future post. Probably part of the same one, actually. Who knows!

Before the Workflow

Before jumping right in, you'll need to do a bit of preparation: 

  • Download the template attached here and upload it into your SharePoint site
  • Download the placeholder0.jpg image and upload it into your SharePoint site
  • Set-up an image library for your photos to go into, and ensure that you have a column for a unique Form ID

Create The Workflow

Our workflow will have 4 main elements:

  1. Send the image attachments to a library;
  2. Go through the image URLs;
  3. Go through the captions;
  4. Build the document via DocGen

1 - Sending the Image Attachments to a Library

  • Use "Copy to SharePoint" action
  • Ensure that you have "Copy Item Metadata" checked
  • Select your image library as the place to copy to

2 - Going Through the Image URLs

  • Set up 10 single line of text variables called Image1, Image2, etc, all the way up to Image10 - however - ensure also that you set the "default value" to the URL of placeholder0.jpg (from our Before the Workflow steps.) If you don't the workflow will error!
  • Set up 1 single line of text variable called Image0 - this is just where we'll move the URLs to & from
  • Set up 1 collection variable for your image URLs
  • Set up 1 num variable for your Index

  • Use the "Query List" action and point it to your Photo library - filter by the unique Form ID, sort by ID, and drop the "Encoded Absolute URL" field into your collection

  • Now that we have our collection, it's time to party! Initialize your Index by setting it to 1 using the "Set Variable" action
  • Create a "For Each" action and set it as follows:
    • Target Collection: Image URLS collection
    • Store Result In: Image0 variable
  • Create a "Switch" action and base it on the Index variable you created. Create a branch for 1 through 10, and an "Other"
  • In each branch, use a "Set Variable" action to set the appropriate numbered variable (ie, Image3 in path 3). Image0 will carry the data we need in each path. The action should read: Image2 is equal to Workflow Data: Image0
  • Use a "Calculate" action to add 1 to the index variable.

3 - Go Through the Captions

This is basically the same as the Image URLs bit, with one main difference... we're dealing with a repeating section now!

  • Create multi line text variables for Cap1 - Cap10.
  • Create 1 multi line text variable called Cap0 (this will be our holding variable)
  • Create 1 num variable to store a count of the items (the children) in the repeating section
  • Re-initialize your num Indexing variable (from before) to 1
  • Use the Repeating Sections UDA to get captions from the repeating section of your form. (Detailed articles on this topic at the bottom of this post.) Be sure to get your caption children into the count variable!
  • Create a "Loop" action and configure it as follows:

  • Add a "Query XML" action and Query your repeating section data (from the UDA)
  • Use //Items/Item[{WorkflowVariable:numIndex}]/NameOfYourCaptionEntryField to get items from your data, and, store it in Cap0
  • Again, just as before, use a switch with paths 1 - 10 and "Other", then set each unique caption variable with the "Cap0" data being passed through.
  • Use the "Calculate" action to add 1 to the Index after each pass

4 - Build the Document via Doc Gen

  • Add the Document Generation action to your workflow
  • Choose the Generation Type of "Original File Types"
  • Click on "Add Document Template" and browse to the template you uploaded earlier
  • Use a workflow data variable for your Output File Name - I suggest using the FormID!
  • Choose an Output location for your document to go to.

Since the template I created for you is already tagged with Cap1 - Cap10 and Image1 - Image10, you don't need ( i think ) to make any changes to see it work with your own form attachments.  ....You probably will want to remove my logos though  

Save & Publish!

Congratulations, you now have a tidy little document with 2 resized pictures per page alongside their captions.  This simple workflow could save your colleagues up to 30 minutes per document generated. Check it out!

Further Reading

TopicAuthorLink
Parsing Repeating Sections - O365Vadim TabakmanParsing Nintex Forms Repeating Section Solution - O365 
Parsing Repeating Sections - On-PremVadim TabakmanNintex Forms/Workflow - Parsing Repeating Section Data - Vadim Tabakman 
15 Comments
vadim_tabakman
Nintex Newbie

Great googamooga!!! This is an awesome post Rhia!!

Vadim

sporcincula
Nintex Newbie

Nicely done, Rhia!  For those that do not have DocGen activated yet, be sure to reach out to your dedicated Nintex Account Manager to setup!

ryan_oleary
Nintex Newbie

Awesome blog, ‌ thanks for contributing!

thomas_clark
Nintex Newbie

This is an awesome blog.Great contribution Rhia!

rhia
Nintex Newbie

Thank you, Nintex employees! Hahahah. I wonder if any users found this useful!? I hope so!

stevena_jhg
Nintex Newbie

does this embed attachments to the form?

stevena_jhg
Nintex Newbie

why does the action "Copy to SharePoint" and "Update Word Document" not show up in my workflow?

vadim_tabakman
Nintex Newbie

Hey Steven,

Those actions are "Enterprise" actions.  It's possible that you currently only have a "Standard" license.

The other option, is that these are on-prem Enterprise actions. If you are on O365, those actions don't exist.

Vadim

stevena_jhg
Nintex Newbie

hi we are on O365.. is there any other way to embed attached pictures to a form to print to pdf

vadim_tabakman
Nintex Newbie

To use the Print to PDF functionality.... I'm just spit balling this idea, as I haven't tried it.

But you'd have to have a form with picture controls on it, configure to look for specific file names, and then have a workflow copy the attachments to the location that the form expects them to be.

That should make them automatically appear, if you open the instance of the form later to do the Print to PDF.

Alternatively, you still have the workflow copy the attachments to a DocLib, and you add some JavaScript to the form, to go and dynamically add HTML image controls to the forms, on-load. 

Vadim

rhia
Nintex Newbie

Just wanted to post an update here: now that the Image URL variable is available in 2013 & 2016, this is waaaay easier! So unless you are in one of those companies that refuses to upgrade, you won't need this post Smiley Happy

c_odegard
Nintex Newbie

Hi Rhia,

Can you explain a little more about how the image resizing works in this flow? It's not working on my end and I'm not sure what I missed.

Also, what do you mean exactly about the "Image URL variable"?

Rhia Wieclawek wrote:

Just wanted to post an update here: now that the Image URL variable is available in 2013 & 2016, this is waaaay easier! So unless you are in one of those companies that refuses to upgrade, you won't need this post Smiley Happy

rhia
Nintex Newbie

Hi Chris!

You managed to respond to this post right as I was looking at the forum - so - great timing!

So, two things: 

1) Image resizing. I have never been able to get this to work using tables. I've been told it should work but I have tried it every way under the sun without luck. The way I go about it is to store all of my images in a SharePoint image library and then use RegEx to modify the URL to have /_w/imagename_jpg.jpg in it, in that form. That gives us a "web ready" size which works for reports very nicely. It's a good size.

2) Image URL variable. This is a data type in the "Tables" section of the Document Generation action. So you will probably have a Single Line of Text variable which will hold your actual Image URL (see from the above), you will then store each of these in a collection (maybe collImageURLs) -- the important part is that in order for DocGen to render them, you need to set their data type as "Image URL" inside of the "Table" settings. 

Let me know if that helps.

Cheers,

rhia

c_odegard
Nintex Newbie

Hi Rhia,

Thanks for the clarification- and yes, your timing is excellent!

The image resizing trick is neat and works for me. I used the following RegEx pattern to get the .../_w/... URL:

  (^http.*LibraryName)(/.*)(\.)(\w{3,}$)

... and the following Replacement Text:

   $1/_w$2_$4.jpg

This is very helpful, but I do wish Nintex would recognize the ImageRendition URLs also. For example, I don't think I would be able to use ".../image.jpg?RenditionID=5" as the Image URL Variable, because it doesn't end with a recognized image extension.

rhia
Nintex Newbie

I wish the same as you, and, that's correct... it would not work, unfortunately! I wish we could resize within DocGen itself somehow. If I could say "all photos should be 600 x 800" and have DocGen scrunch them to that, that'd be great.

Also, thanks for sharing your RegEx! I do it in a much less mature way... much less pretty.