37
Views
3
Comments
Solved
[XML Records] RecordToXml with record containing lists doesn't iterate correctly
xml-records
Service icon
Forge asset by Afonso Carvalho
Application Type
Reactive
Service Studio Version
11.54.43 (Build 63110)

I have an object with invoices that contains a list of which the list items contain nested lists. The whole thing should result in an Xml that, simplified, looks like this:

<Root node>
    <Invoice>
        <Id>1</Id>
        <InvoiceLine>
            <Id>1.1</Id>
        </InvoiceLine>
        <InvoiceLine>
            <Id>1.2</Id>
        </InvoiceLine>
    </Invoice>
    <Invoice>
        <Id>2</Id> 
        Etc.

The structure I use to create this record seems to work correctly. However, when I use RecordToXml, something weird happens to the list. It does generate a list with multiple invoices however it overwrites the data of the first Invoice: the data in the first invoice receives the same data as the second one. The InvoiceLine list does work correctly, this shows the data belonging to (what should be in) the Invoice.

To illustratie, the Xml above turns into this:

<Root node>
    <Invoice>
        <Id>2</Id>
        <InvoiceLine>
            <Id>1.1</Id>
        </InvoiceLine>
        <InvoiceLine>
            <Id>1.2</Id>
        </InvoiceLine>
    </Invoice>
    <Invoice>
        <Id>2</Id> 

Is this to do with the XmlConfig? I can't figure out how to use that.

UserImage.jpg
Philip Stuij
Solution

Yes it appears to work correctly from the start but somehow one node is overwritten but not its sub node.

I found a senior co-worker who's willing to take a look at this with me tomorrow. If that fails, I'll see about that demo. If it works, I'll post the solution.

2019-06-15 21-39-22
Afonso Carvalho
 
MVP

Hello Philip,

It's strange that the inner list is working correctly. Do you think you could create a demo module showcasing the issue?

UserImage.jpg
Philip Stuij
Solution

Yes it appears to work correctly from the start but somehow one node is overwritten but not its sub node.

I found a senior co-worker who's willing to take a look at this with me tomorrow. If that fails, I'll see about that demo. If it works, I'll post the solution.

UserImage.jpg
Philip Stuij

Co-worker was able to fix it while I was out. Apparently, the record used for creating the Xml looked OK but really wasn't. The exact cause is still a bit of a mystery but by assembling the record data differently (by creating lists and appending them to the record rather than assigning directly) we got it to work.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.