dan.stoll

Diving a little deeper into Document Generation

Blog Post created by dan.stoll Employee on Dec 17, 2015

Well hopefully you have already had a quick look at It's here... Nintex Document Generation and had a play around with the Doc Gen action in Office 365. With this post I'm going to go a little deeper and try to explain how to get repeating section data from a Nintex Form into a table in a document. Kok Koon Gan just posted a great post as well detailing Using Document Generation to create Excel Report from List Items.

 

Continuing on from It's here... Nintex Document Generation  I'm going to use the same example and template, but just change it up, just a little.

 

The thing you have to get in your head early in this process is that to have a table in a document you have to build up a collection of data that can be inserted in.. Now for those of you that have worked with Collections, you'll know that it is just an array.. Eg One, Two, Three, Four etc. So knowing this, how do you get multiple columns into a table ? We have dictionaries, these are close to what we need, but we can't use the Query XML action and put the data from a repeating section into a dictionary in a meaningful way as we cannot specify what the key is.. What we actually need to do is may sounds a little confusing, but once you have done once or twice it will make a bit more sense..

 

Now if you haven't done this already, connect your repeating section inside your form to a Multiline text field (Plain). This can be a hidden filed in the content type if you wish.

 

Here you can see the fields I have in my repeating section:

And then populated.

 

In a XML world it looks a bit like this :

 

<?xml version="1.0" encoding="utf-8"?><RepeaterData>
<Version />
<Items>
<Item>
<ItemId type="System.String">8675309</ItemId>
<ItemRating type="System.String">Bad</ItemRating>
<ItemNotes type="System.String">Graffiti on wall.</ItemNotes>
</Item>
<Item>
<ItemId type="System.String">6060842</ItemId>
<ItemRating type="System.String">Bad</ItemRating>
<ItemNotes type="System.String">Intermittent disconnections.</ItemNotes>
</Item>
</Items>
</RepeaterData>

 

Using the "Query XML" action and a little XPath, we can pull the values out of the XML like this:

 

Notice the XPath string :

 

/RepeaterData/Items/Item/ItemId

 

What this will do is pull all the ID values into a Collection called 'IdCol'. Now you have to do the same for the other values you wish to place in your table. For this example that means I need a collection for the ID, Rating and Notes.

 

Once I have those collections, I need to put these into a dictionary.. WHY?? you ask.. Well, this allows me to form up the data with a 'Key' for which I need when trying to reference specific data in my document.

 

To picture this we have this in Collections Variables:

IdCol = 8675309;6060842

RatingCol = Bad;Bad

NotesCol = Graffiti on wall.;Intermittent disconnections.

 

Now we need to put this information in a dictionary as so we can assign keys,, So we need to put the collections through "For Each" loop. I'm assuming you know how this works here.. So in simplistic terms, the loop will cycle through a collection variable pulling the values out and putting them into a Text Variable, and keep running until there are no values left. Using this with an Index, we can grab other values out of other collections to build out our related data.

 

As you can see in the above graphic we also have a Build Dictionary action.

 

 

With the "Build Dictionary" action I'm grabbing the Single Line Text values from the collections and putting them in the dictionary but associated with a key. So after my loop is finished I will have a dictionary variable with the following value.

 

ItemsFinal (Dictionary Variable) = {"Id":"6060842","Rating":"Bad","Notes":"Intermittent disconnections."}

 

Then by adding an "Add item to Collection" action to the loop I can grab my newly formed dictionary value and place it back into a collection, looping on itself thus adding all the new individual dictionary values to the collection with a delimiter.. The big difference now is that I have a single collection that is nicely formed with all my collection data paired with a dictionary key.

 

FinalCollection (Collection Variable) = [{"Id":"8675309","Rating":"Bad","Notes":"Graffiti on wall."},{"Id":"6060842","Rating":"Bad","Notes":"Intermittent disconnections."}]

 

Ok so that was the hard bit.. , and I hope you haven't been confused by it all.. It took me a couple of tries and a few "please help" emails to get my head around it..

 

Now for the easy part.. Building out the document, and in our case the word doc.

 

Opening up the Document Generation action as per It's here... Nintex Document Generation, for a repeating table of info the first thing we need to do is set the magic tag to tell the table that there is more coming

 

In the table it looks a little like this

We then need to go through and add our other tags to the table, and this is where the Keys come in.

 

 

Using the Keys from earlier, build out the rest of the table

With the table built out, save the template and go run that workflow..

 

That's all there is to it .. Until next time, happy nintexting

Outcomes