How to use field value as parameter name

Hello! I have a JSON datasource in this format:

{
  "data": [
    {
      "id": 0,
      "images": ["IMAGE_0", "IMAGE_2"]
    },
    {
      "id": 1,
      "images": ["IMAGE_1"]
    },
    {
      "id": 2,
      "images": null
    }
  ]
}

I create subreport for each value in images array and assign this value to a field named "node". So I have subreports 0 with node = "IMAGE_0", 1 with node = "IMAGE_2", 2 with node = "IMAGE_1" and 3 with node = null. These subreports contains image elements. I am using parameters IMAGE_0, IMAGE_1, ..., IMAGE_N to pass byte data of images from my Java code. I want first subreport to use $P{IMAGE_0} and $P{IMAGE_2} as source expressions for image content. How can I create expressions like this given "node" fields? Something like $P{$F{node}} which would be evaluated to $P{IMAGE_0} for node = "IMAGE_0"

usernam123345's picture
Joined: Feb 27 2023 - 11:50pm
Last seen: 6 months 1 week ago

2 Answers:

I'm not sure it's possible the way you described - Parameters in JRS are like variables in Java - they are defined at the beginning of report processing and Fields are not available until after the Report is processed and a result (from the dataset/query) is obtained. So you can't change the names of Parameters after it's run the report. However you CAN pass your Field values to a subreport AS a Parameter in that subreport. Wouldn't that accomplish what you want?

mbielkiewicz's picture
Joined: Feb 23 2014 - 9:22pm
Last seen: 4 days 16 hours ago

Thank you for answer. I ended up using REPORT_PARAMETERS_MAP built-in parameter like this $P{REPORT_PARAMETERS_MAP}.get($F{node})

usernam123345's picture
Joined: Feb 27 2023 - 11:50pm
Last seen: 6 months 1 week ago
Feedback