cancel
Showing results for 
Search instead for 
Did you mean: 
janp
Nintex Newbie

Parsing Repeater XML

Jump to solution

Hi,

I've been trying to read repeater xml following Vadim's blog at  http://www.vadimtabakman.com/nintex-formsworkflow-parsing-repeating-section-data.aspx but I can't get it work correctly.

For test I have 3 fields - txtFirstName, txtLastName and txtAge (numeric)

The repeater is called repTest

I query get the FormData and use the inline function fn-XMLDecode and set it to a variable that I would then like to use XML Query on.

When I query that variable I can only seem get results if I use //repTest     (which is the name of the repeater control)

If I use any other XPath expression I don't get any results. (with the exception of node() and //*)

example:

Form Data
<?xml version="1.0" encoding="utf-8"?><RepeaterData><Version /><Items><Item><txtFirstName type="System.String">first</txtFirstName><txtLastName type="System.String">last</txtLastName><txtAge type="System.Int32">11</txtAge></Item><Item><txtFirstName type="System.String">first2</txtFirstName><txtLastName type="System.String">last2</txtLastName><txtAge type="System.Int32">22</txtAge></Item></Items></RepeaterData>

Decoded Form Data
<?xml version="1.0" encoding="utf-8"?><RepeaterData><Version /><Items><Item><txtFirstName type="System.String">first</txtFirstName><txtLastName type="System.String">last</txtLastName><txtAge type="System.Int32">11</txtAge></Item><Item><txtFirstName type="System.String">first2</txtFirstName><txtLastName type="System.String">last2</txtLastName><txtAge type="System.Int32">22</txtAge></Item></Items></RepeaterData>

//repTest
firstlast11first2last222

//repTest//txtFirstName


//repTest/*

I've tried variations with //RepeaterData/Items/Item etc. (as per the xpath builder)

I've also tried just running a query on  the decoded xml document (just pasted the xml shown in "Decoded Form Data into the XML Query source) and XPath like //txtFirstName. This works fine.

I'm assuming I'm missing an in between step to get the XML properly formatted. I thought I was doing that by using the build string action and fn-XMLDecode but I'm not having any luck with it.

Labels: (2)
Tags (1)
Reply
24 Replies
Automation Master
Automation Master

Re: Parsing Repeater XML

Jump to solution

If you want to use the Query XML action, your XML has to look like the one you posted under Decoded Form Data.

You can use this formula to get the XML of each line of your repeating section in a collection variable (return results as Outer XML) :

//Item

You can then loop through each line (via executing a foreach action on your collection variable) and query the XML of each line to get the value of the fields with this formula (return results as Text):

//TheNameOfTheControlInsideYourRepeatingSection

You can also connect your repeating section to a multi line column and then the XML will be stored in this column (you won't need to read the FormData column and extract the part corresponding to your repeating section).

Hope this helps

Reply
janp
Nintex Newbie

Re: Parsing Repeater XML

Jump to solution

Thanks Caroline,

I have since been able to iterate through the items using the multi line plain textbox. I just couldn't get any xpath to work on the form data other than the //repeaterControlName. (i.e. I could not get //Item, //repeater//Item, //controlInsideRepeater, etc. to work)

I will use that for now and look into what I'm doing wrong afterwards.

I also noticed that some xpath functions error out - count(//Item). I'm using xslt to accomplish what I need but xpath less typing . Will these functions ever be implemented? (or is it that I'm just using them incorrectly)

0 Kudos
Reply
Automation Master
Automation Master

Re: Parsing Repeater XML

Jump to solution

Hi Jan,

I've actually seen that before too when using Form Data directly.   I usually go straight to the multi-line text now since it seems to be more consistent and has never had that issue.

-Mike

Reply
allan48728
Nintex Newbie

Re: Parsing Repeater XML

Jump to solution

Thanks Caroline! That was very helpful. I haven’t found many posts that are detailed in how to properly use the “For Each” and “Collection” variable.

For anyone else reading this, here’s a little more information building on what Caroline said, and is how you might create a For Each workflow that parses the XML. These steps are in the order that you should add the workflow actions with “Set variable” being at the top of the workflow workspace sequence.

  1. Add a “Set variable” action and set a multi-line variable (e.g. “MLOT_XMLDump”) Equals Value [insert your list item XML field which is populated from the repeating section being Connected To it in Nintex Forms Designer].
  2. Create a “Build String” action immediately below with Text being fn-XmlDecode({WorkflowVariable:MLOT_XMLDump}) and Store result in MLOT_XMLDump. This is to remove strange characters from the XML.
  3. Create a “Query XML” action where the XML field is {WorkflowVariable:MLOT_XMLDump} and the Output 1 formula is //Item, and where “Store result in” is your new collection variable (e.g. Collection_Item).
  4. Create a “For Each” action where the “Target collection” is your collection (e.g. Collection_Item) and Store result in is MLOT_Item (a new multiline variable).
  5. Within the “For Each” action, for XML put {WorkflowVariable:MLOT_Item}, for Output 1 set the formula to //TheNameOfTheControlInsideYourRepeatingSection and Store result in (yourNewVariable). Add as many Outputs as you'd like.
  6. Now you have your variables containing the XML values, and you can now add for example an "Update Item" or "Set field value" action to update values in a list item as needed.

A couple other posts on using “For Each” and a “Collection” variable are below. For Each is the fastest method to parse the XML (except if you somehow use client-side Jquery instead):

https://community.nintex.com/message/26604#26604

https://community.nintex.com/message/16949#16949

This one suggests a “Loop” (which can be very slow if you have safe looping enabled):

http://www.vadimtabakman.com/nintex-formsworkflow-parsing-repeating-section-data.aspx

Reply
Nintex Employee
Nintex Employee

Re: Parsing Repeater XML

Jump to solution

Hi Allan,

fair call on the Loop being slow when Safe Looping is enabled.  I don't know what that guy was thinking in that blog post

You could instead use the Query XML action to pull out all the details into Collection variables, then parse them with a For Each action, that doesn't get affected by Safe Looping.

I have been doing that more and more, since it's pretty easy to parse related collection variables : Nintex Workflow - Iterate through Related Collections - Vadim Tabakman

Vadim

Reply
Automation Master
Automation Master

Re: Parsing Repeater XML

Jump to solution

Hi Allan,

I'm glad I could help.

Don't hesitate if my explanations are not clear enough .

Thanks for adding details, it will help the community.

Have you tested without the first two steps you've written and in the "Query XML" action, directly add the reference to the item column connected to your repeating section? (I've alway do that without your first two steps)

Vadim is absolutely right : with his method you will only have one "Query XML" action and one "For each" action.

Reply
allan48728
Nintex Newbie

Re: Parsing Repeater XML

Jump to solution

Thanks Caroline, I'll have to try it again sometime without the first two steps. I ran into an issue where the XML was encoded with extra characters which caused the XML parsing to fail and so it broke my workflow. I then used fn-XmlDecode() which fixed the issue. I had to follow the "Parse that XML" recommendation in the following blog post (and I generally applied this blog post anyway): Best Practices with Repeating Sections in Nintex Forms

0 Kudos
Reply
Automation Master
Automation Master

Re: Parsing Repeater XML

Jump to solution

Great that you could fix your workflow !

Tell me if you have other issues.

Reply
Not applicable

Re: Parsing Repeater XML

Jump to solution

I tried your method and it worked, but instead of appending the field values, it overwrites the previous values displaying only the last item entered in the form's repeating section. Any Ideas?

0 Kudos
Reply