jsonreportsubreporttelerik-reporting

In Telerik Reporting (Desktop), how to inject a json sub-node into sub-report string parameter


Introduction

Based on the below json sample, I am trying to define a Telerik report using both a main report and a sub-report, where se second is fed with a subset of the main report json data.

Basically, data flow mimics something like:

  1. Application injects base json data into main report's jsonData(string) parameter;
  2. jsonData is binded as report datasource;
  3. Json data selector is applied;
  4. Json selected data Employes node is injected into a sub-report, which will also use it as a json data source.

Troubles arose on step 4, where I am getting an [Invalid value of report parameter 'jsonData'] error when main report is rendered.

It seems Telerik Report is unable to convert a selected json node field data into a proper string.

Full context

For full context:

It seems that data selector converts json Employes node date into a System.Object[], which is giving me a nice hard time figuring out how to convert it back to a json string.

I have alread extensively searched on documentation, web, ChatGPT and alikes for a valid solution. So far, no luck.

Before you help me

Although I have the most appreciation for anyones effort trying to helping me:

{
    "Companies": [
        {
            "Name": "Company1",
            "Employes": [
                {
                    "Name": "Joe",
                    "Wage": 1000
                },
                {
                    "Name": "Jack",
                    "Wage": 2000
                }
            ]
        },
        {
            "Name": "Company2",
            "Employes": [
                {
                    "Name": "Mary",
                    "Wage": 3000
                },
                {
                    "Name": "Mike",
                    "Wage": 4000
                }
            ]
        }
    ]
}

Solution

  • Indeed, passing the "Employes" object to the "jsonData" parameter of the subreport should not work because the object cannot be converted to a JSON string directly. You have to convert it thru CStr() function.

    However, instead of using a parameter to set the data source of the subreport, you can use the binding described in the How to Represent Hierarchical Nested Data KB article.

    I also want to mention that in the R3 2022 SP1 release, the DataSource property was added to the SubReport item as well. This makes the approach I suggested above obsolete because it allows you to bind the data source of the subreport directly in the main report. For example:

    Solution 1

    SubReport item binding based on DataSource property:

    Property path: DataSource
    
    Expression: = Fields.Employes
    

    Solution 2

    In @Julio's provided sample, which allows to inject json node as a sub-report parameter, instead of a direct datasource, you should use following approach.

    SubReport item binding thru sub-report parameter:

    Property path: jsonData
    
    Expression: = CStr(Fields.Employes)
    

    Bear in mind that...

    For further details on this subject, check original Telerik's original post