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

1 Answer 381 Views
DataSource JSON Report Designer (standalone) Report Parameters
garri
Top achievements
Rank 2
Iron
Iron
Iron
garri asked on 30 May 2023, 11:43 AM

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:

  • On both reports:

    • There is a jsonData report parameter of string datatype;

    • There is a JsonDataSource defined;

    • Binding between the string jsonData parameter and main JsonDataSource is based upon:

      • Property path: Datasource.Source
      • Expression: = Parameters.jsonData.Value
  • On main report:

    • JsonDatasource $.Companies data selector is being used, resulting in a list representing containing de the companies list, each instance having:
  • Name, a string representing the company name;

  • Employes, an object containing the company employes list.

    • Full sample json data is injected thru jsonData parameter;
  • On sub-report:

    • There is also a jsonData report parameter of string datatype;
    • JsonDataSource $ data selector is being used, which should result in:
      • A list of the following fields:
        • Name, a string representing the name of the employe;
        • Wage, a numeric value representing employe's wage.
  • Again on main-report, I am using the following sub-report parameters mapping:

    • Parameter Name: jsonData
    • Parameter Value: Fields.Employes
  • I am using Telerik Report Designer v15.1.21.716 (Desktop)

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:

  • I am pursuing a json only data source solution. I mean, I am not interested on any other alternative suported Telerik Reporting datasources;
  • Solution must work in both design-time and runtime.
{
    "Companies": [
        {
            "Name": "Company1",
            "Employes": [
                {
                    "Name": "Joe",
                    "Wage": 1000
                },
                {
                    "Name": "Jack",
                    "Wage": 2000
                }
            ]
        },
        {
            "Name": "Company2",
            "Employes": [
                {
                    "Name": "Mary",
                    "Wage": 3000
                },
                {
                    "Name": "Mike",
                    "Wage": 4000
                }
            ]
        }
    ]
}

1 Answer, 1 is accepted

Sort by
1
Accepted
Momchil
Telerik team
answered on 02 Jun 2023, 09:30 AM

Hi Luis,

Thank you for describing your scenario in such detail. It is greatly appreciated.

Indeed, passing the Employes object to the jsonData parameter of the subreport will not work because the object cannot be converted to a string directly.

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 am attaching a sample report that implements this for reference.

Finally, I want to mention that in the R3 2022 SP1 release, we added the DataSource property 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:

SubReport item

  • Property path: DataSource
  • Expression: = Fields.Employes

I hope this helps.

Best Regards,
Momchil
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
garri
Top achievements
Rank 2
Iron
Iron
Iron
commented on 02 Jun 2023, 11:26 AM | edited

Hi Momchil

Indeed, binding sub-report jsonData parameter to expression = CStr(Fields.Employes), as you kindly suggest on the sample you provided, did the trick!

Since a collegue of mine has posted this same question on stackoverflow and is offering a 100 bounty reputation points, on this same question, he asked to suggest you to post this answer overthere, so he can give you the deserved bounty, which I am sure he will be very glad to do so.  Of course, if that that is ok for you.

Your answers is very much appreciated :-)

All best

Luis Garrido

Momchil
Telerik team
commented on 07 Jun 2023, 08:22 AM

Hi Luis,

Thank you for letting me know about your colleague's Stack Overflow question. I have sent my reply there as well.

However, it is strange that setting the jsonData parameter to expression = CStr(Fields.Employes) has worked for you. I used this expression to confirm that the object is not converted properly (CStr(Fields.Employes) returns "System.Object[]" on my end) and simply forgot to remove it from the report before I sent it to you.

The binding I applied to the report referenced by the SubReport item is what actually got things to work.

  • Property path: DataSource
  • Expression: = ReportItem.Parent is Null ? ReportItem.DataSource : ReportItem.Parent.DataObject.Employes

I hope this clarifies things.

 

Tags
DataSource JSON Report Designer (standalone) Report Parameters
Asked by
garri
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Momchil
Telerik team
Share this question
or