AnsweredAssumed Answered

Parse repeating section with For Each?

Question asked by nmjohns on Aug 17, 2017
Latest reply on Aug 17, 2017 by paul.crawford

I'm parsing a Repeating Section with a For Each. Sometimes, a field in the For Each doesn't have data. Sometimes it does. I can't figure out how to capture it correctly. So you can see the XML from the Repeater Section below. 

 

<?xml version="1.0" encoding="utf-8"?><RepeaterData><Version />
<Items>
<Item>
<dtlCurrentRowNumber type="System.String">1</dtlCurrentRowNumber>
<txtchoiceGetMethodAdded type="System.String"></txtchoiceGetMethodAdded>
<txtchoiceRegionAdded type="System.String">REGION</txtchoiceRegionAdded>
<txtchoiceLTCAdded type="System.String">**SelectValue**</txtchoiceLTCAdded>
<txtchoiceCentersbyRegionAdded type="System.String">CENTER001;CENTER002</txtchoiceCentersbyRegionAdded>
<txtchoiceCentersbyLTCAdded type="System.String"></txtchoiceCentersbyLTCAdded>
<dtlAddedText type="System.String">111</dtlAddedText>
</Item><Item>

<dtlCurrentRowNumber type="System.String">2</dtlCurrentRowNumber>
<txtchoiceGetMethodAdded type="System.String"></txtchoiceGetMethodAdded>
<txtchoiceRegionAdded type="System.String"></txtchoiceRegionAdded>
<txtchoiceLTCAdded type="System.String">LTCTYPE</txtchoiceLTCAdded>
<txtchoiceCentersbyRegionAdded type="System.String"></txtchoiceCentersbyRegionAdded>
<txtchoiceCentersbyLTCAdded type="System.String">CENTER002;CENTER003;CENTER001;CENTER004</txtchoiceCentersbyLTCAdded>
<dtlAddedText type="System.String">222</dtlAddedText></Item></Items></RepeaterData>

 

I'm then doing a query on //txtChoiceCentersbyRegionAdded and //txtchoiceCentersbyLTCAdded. 

I log the results of the query to make sure I'm returning the correct information. My log then looks like this:

 

8/17/2017 9:26 AM Comment  Centers Region: CENTER001;CENTER002
8/17/2017 9:26 AM Comment  Centers Region:  
8/17/2017 9:26 AM Comment  LTC Centers:  
8/17/2017 9:26 AM Comment  LTC Centers: CENTER002;CENTER003;CENTER001;CENTER004
8/17/2017 9:26 AM Comment  Combined: ;CENTER002;CENTER003;CENTER001;CENTER004

So far so good. I can see it checked both Items returned in the XML, and it pulled the Centers for each item. Line 1 and 3 are the same item. Line 2 and 4 are the second item.

 

Line 2 shows where no CentersbyRegion were selected. Line 3 shows no CentersbyLTC added. All that is correct. Line 5 is my current problem. 

 

Line 5 in the log is a Build String set to "vartxtChoiceCentersbyRegionAdded;vartxtchoiceCentersbyLTCAdded". You can see an empty space for "vartxtChoiceCentersbyRegionAdded" and then the semicolon and the correct output for "vartxtchoiceCentersbyLTCAdded". I understand why this is happening. It's because Item 2, there was no data to put into "vartxtChoiceCentersbyRegionAdded" so it essentially erased the variable contents. 

 

What is the best way to save the results here? I'm going to have the possibility of up to about 10 different Items in the Repeater, some will have data, some will be blank. I need to save each Item data for both fields in the Repeater and concatenate them all into one, remove duplicates, and have my final list. 

Outcomes