cancel
Showing results for 
Search instead for 
Did you mean: 

How To: Injecting XML Data into a Repeating Section

Workflow Hero
0 0 350

In a previous blog we discussed How To: Extract XML Data from a Repeating Secion. This time I wanted to take a look at how we can inject data into that same repeating section and form to add more lines without having the user manually enter them. We can accomplish this once we understand the data structure and how it is being built. From there, we can simply create new items within the data and post it back to out list. Let's dive in!

 

Scenario

I have multiple items that I need to inject into a repeating section within my Nintex Forms. This will allow for a single view of items for approval or review.

 

If you followed along on my last blog, you will already have all that you need!

 

Form

Great part about this is everything has already been done on the form and you are all set to go. Keep in mind that any fields you add to yout repeating section will need accounted for if you intend on injecting data later on.

 

List

Last time we did not talk much about the list, but take a moment and display the column you are using to capture the XML data from your repeating section. Last time we use RepeatingSectionXML.

 

It should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<RepeaterData>
	<Version />
	<Items>
		<Item>
			<BankName type="System.String">Texas State Bank</BankName>
			<Location type="System.String">Odessa</Location>
		</Item>
		<Item>
			<BankName type="System.String">Heritage Bank</BankName>
			<Location type="System.String">Erlanger</Location>
		</Item>
		<Item>
			<BankName type="System.String">Banner Bank</BankName>
		<Location type="System.String">Walla Walla</Location>
		</Item>
		<Item>
			<BankName type="System.String">Colonial Bank of Waterbury</BankName>
			<Location type="System.String">New Canaan</Location>
		</Item>
		<Item>
			<BankName type="System.String">Monroe Bank</BankName>
			<Location type="System.String">Monroe</Location>
		</Item>
		<Item>
			<BankName type="System.String">Home Federal Savings Bank</BankName>
			<Location type="System.String">Rochester</Location>
		</Item>
	</Items>
</RepeaterData>

 

Now, to add some extra items into this!

 

There are a few ways to go about doing this. Of course we could simply open the form and add items, but we want to avoid that. We could manually do it. Just edit the column within SharePoint and save the changes. We also could do it from a workflow. Perhaps grab some extra data and then inject it back into the column. Let's take a look at doing something via the workflow!

 

Workflow

For this we want to start with a grabbing the current XML data so that we can keep it in the form (don't want to lose that!) and building out a new XML data structure that we can then pass back into our list item. We do this by leveraging the Query XML action and set it up like this:Inner XML.PNGQuery Inner XML

You'll notice that I am grabbing the Inner XML from this node as we want to loop through each to ensure it is being added to our final output. Now that we have the data for the "body" of our XML, we just need to piece it back together and inject data where needed. First, let's start with the XML and how we can piece it together. 

 

Using a Build String action, we want to start to construct our data structure for the XML we are going to use. If you are unsure how to do this, simply look at the RepeatingSectionXML column in your list and use that as a baseline. It will look something like this:Open XML.PNGOpening XML

 

Now lets populate the nodes we want to keep with the data we already queried above. I am using a loop to go through each node and add it to my string variable (updatedXML). You can inject data at this point if you wanted to, you just need to know the data types and values that you wish to inject. I am going to do this in another step to keep it clean. Your loop should be similar to this:For Each Loop.PNGFor Each Loop

 

XML structure.PNGBuild XML Structure

Again, notice that we are taking each line item and adding to the existing updatedXML variable. Be sure to add in the <Item></Item> tags around each item you want to add!

 

Last thing to do is to make sure all your nodes have been closed with the proper tags...but before we do that, let's inject some new data!

 

Now keep in mind that my form is only accounting for Bank Name and Location, so I can only inject those two data points. If you want to add more, you would need to alter the form to account for those changes. For me, I am going to do a quick lookup to another list and grab a bank and it's location and inject it into this form's repeating section (my XML data).  Once I do my lookup and have my variables, I simply use a Build String action to create another item within my XML like so:New Item XML.PNGNew Item Added to XML

Again, we add this new data onto our existing updatedXML variable. This time we have to provide a bit more details around the data and types (take a look at your RepeatingSectionXML list column if you need to see how your data is setup).

 

Now we can close the XML off with our last Build String action:

Close XML.PNGClose XML

 

Don't forget to update your list item! With the newly crafted XML data, we can use the Item List Item action and update the RepeatingSectionXML column.

Update List Item.PNGUpdate List Item with New XML

 

Updated XML data will look like this:

<?xml version="1.0" encoding="utf-8"?>
<RepeaterData>
	<Version />
	<Items>
		<Item>
			<BankName type="System.String">Texas State Bank</BankName>
			<Location type="System.String">Odessa</Location>
		</Item>
		<Item>
			<BankName type="System.String">Heritage Bank</BankName>
			<Location type="System.String">Erlanger</Location>
		</Item>
		<Item>
			<BankName type="System.String">Banner Bank</BankName>
			<Location type="System.String">Walla Walla</Location>
		</Item>
		<Item>
			<BankName type="System.String">Colonial Bank of Waterbury</BankName>
			<Location type="System.String">New Canaan</Location>
		</Item>
		<Item>
			<BankName type="System.String">Monroe Bank</BankName>
			<Location type="System.String">Monroe</Location>
		</Item>
		<Item>
			<BankName type="System.String">Home Federal Savings Bank</BankName>
			<Location type="System.String">Rochester</Location>
		</Item>
		<Item>
			<BankName type="System.String">This is a test</BankName>
			<Location type="System.String">Testing City</Location>
		</Item>
	</Items>
</RepeaterData>

 

You can run your update (whether it was manually or via workflow) and you should now see the updated XML reflected in your Nintex Form!

 

New Banks Added.PNGUpdated XML in Form

I hope this helps you in understanding how you can dynamically inject data into your repeating sections in Nintex Forms and how you use XML to get or update data.

 

Until next time!