Issue with outputting sequential data (different array items) using LINQ reporting engine

I have an issue with outputting sequential data from an array with different items (each item has a different set of fields). I attached an archive with the template, JSON, log, and code.
support.zip (12.1 KB)

@bz.anton.kh

It seems you’re facing an issue with outputting sequential data from an array using the LINQ reporting engine, particularly when each item has a different set of fields. While I can’t directly address your specific code or template without seeing them, I can suggest a general approach.

When working with LINQ reporting, ensure that your data structure is flexible enough to accommodate the varying fields of each item. You might consider using a dynamic type or a dictionary to represent each item, allowing you to access fields dynamically based on their existence.

Here’s a simple example of how you might structure your data:

var data = new List<Dictionary<string, object>>
{
    new Dictionary<string, object>
    {
        { "Field1", "Value1" },
        { "Field2", "Value2" }
    },
    new Dictionary<string, object>
    {
        { "FieldA", "ValueA" },
        { "FieldB", "ValueB" },
        { "FieldC", "ValueC" }
    }
};

// Use LINQ to process this data as needed
var result = data.Select(item => new
{
    Field1 = item.ContainsKey("Field1") ? item["Field1"] : null,
    FieldA = item.ContainsKey("FieldA") ? item["FieldA"] : null
});

This approach allows you to handle different fields for each item without running into issues with missing properties.

For more specific guidance, I recommend consulting the official documentation on LINQ reporting and data binding, which may provide additional insights into handling such scenarios.

I’m using a huge input JSON with JsonDataSource. I added ReportBuildOptions.ALLOW_MISSING_MEMBERS to prevent errors when some fields are missing, but it didn’t help.

@bz.anton.kh Please try modifying your template like this:

<<foreach [ca in contact.array]>>
	<<[ca.firstName]>>
	<<[ca.lastName]>>
	<<[ca.address]>>
	<<[ca.job?.title]>>
<</foreach>>

Modified, looks good, but I have another issue with foreach and a various set of items.
support.zip (12.2 KB)

@bz.anton.kh If modify the template like this, the template is filled with data properly:

<<foreach [item in object.array]>>
	<<[item.fields?.field1?.value]>>
	<<[item.fields?.field2?.value]>>
<</foreach>>

Hi, it looks like all issues are resolved! Many thanks!

1 Like