rhia

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

Blog Post created by rhia Champion on Jun 19, 2017

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

Outcomes