We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Nested foreach does not work with JSON Data Source using .NET | LINQ Reporting Engine

Hello,

can you explain me the following behaviour?
The Json:

    {

    	"Articles": [
    		{
    			"Nr": 1,
    			"Name": "Product A",
    		},
    		{
    			"Nr": 2,
    			"Name": "Product B",
    		},
    		{
    			"Nr": 3,
    			"Name": "Product C",
    		}
    	],
    	
    	"Persons": [
    		{ "Name": "Person A" },
    		{ "Name": "Person B" }
    	]	
    }

Word Template Syntax:

    <<foreach [p in Persons]>>
        <<[p.Name]>>

       No output because nested foreach:
       <<foreach [a in Articles]>>
            <<[a.Nr]>>
           <<[a.Name]>>
        <</foreach>>

    <</foreach>>

When you include a foreach in foreach then the inner foreach is it is always empty.
Seems like a bug to me.

Maybe you can explain the behaviour or confirm the bug.

Thank you

@kamal777

You are facing the expected behavior of LINQ Reporting Engine. We suggest you please read the following article.

The JSON data source should have parent child relationship as shown in following JSON:

    [
        {
            Name: "John Smith",
            Contract:
            [
                {
                    Client:
                    {
                        Name: "A Company"
                    },
                    Price: 1200000
                },
                {
                    Client:
                    {
                        Name: "B Ltd."
                    },
                    Price: 750000
                },
                {
                    Client:
                    {
                        Name: "C & D"
                    },
                    Price: 350000
                }
            ]
        },
        {
            Name: "Tony Anderson",
            Contract:
            [
                {
                    Client:
                    {
                        Name: "E Corp."
                    },
                    Price: 650000
                },
                {
                    Client:
                    {
                        Name: "F & Partners"
                    },
                    Price: 550000
                }
            ]
        },
        {
            Name: "July James",
            Contract:
            [
                {
                    Client:
                    {
                        Name: "G & Co."
                    },
                    Price: 350000
                },
                {
                    Client:
                    {
                        Name: "H Group"
                    },
                    Price: 250000
                },
                {
                    Client:
                    {
                        Name: "I & Sons"
                    },
                    Price: 100000
                },
                {
                    Client:
                    {
                        Name: "J Ent."
                    },
                    Price: 100000
                }
            ]
        }
    ]

Template document :

<<foreach [in managers]>>Manager: <<[Name]>>
Contracts:
<<foreach [in Contract]>>- <<[Client.Name]>> ($<<[Price]>>)
<</foreach>>
<</foreach>>

Source code:

Document doc = ...              // Loading a template document.
JsonDataSource dataSource = ... // Loading JSON.
    
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, dataSource, "managers");