JasperReports: How to dynamically change subreportExpression - dynamic

What I am trying to do is seemingly simple.
I have a master report that includes a subreport element. The subreport is populated from a JRAbstractBeanDataSource, that has a collection of 0-n subreports in it.
In the master report, the subreport is found with:
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + $F{subReportFileName}]]></subreportExpression>
This works fine, SUBREPORT_DIR is passed in as a param to the datasource in the code.
What I need to do though, is select a different report name, based on the subreport properties, something like:
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "$F{subReportFileName}"]]></subreportExpression>
That is, allow each item in the collection of subreport datas on the datasource specify what the .jasper filename will be (that is, allow it so select which subreport to use).
Maybe there is a better way to think about/approach this.

Just a side note - when you want to include code in your question, use the code button above the composition window. We can't see your example. If you click on the question mark inside the little orange square at the top right corner of the composition window it will take you to a Markdown editing tutorial.
I'm a little unclear as to what you are trying to accomplish. I'm not sure from the collection if you want to include all the subreports in your report and need a way to iterate through their names in the directory, or if you want the selection of the subreport to be dynamic. I don't know of a way to include more than one subreport in a main report. If you want to dynamically select the report name, why not just make the subreport name a parameter that gets passed to your report from your code. You can do your logic to decide which report name you want based on whatever criteria you choose. If that's not what you're looking for, perhaps a little more detail in your question would help.

I was trying to find a way to set the report name as the master report iterated over the date source items. Instead I just made the query completely dynamic, passed in as a param. That's what I really needed to change for each sub-report.

Related

Holding parameter values when report is refreshed due to custom buttons used for expand/collapse groups

This may be as simple as it can't be done, but I have to ask. :) I am building a report using Report Builder 3.0. The report contains a table which also has Grouping established. I wanted to give the user an easy way to expand/collapse all rows of the table, so I used the method of creating a parameter with two values (0 for collapse, 1 for expand), tied the visibility of the group to the parameter using an expression in the Hidden Property for the group. Then I created two text boxes for Expand and Collapse and added the respective parameter/value in the Action in the text box properties.
At this point, everything works as intended. Here is where I run into the issue. I added another parameter, lets just call it "Location". The parameter is a text data type that allows multiple values and gets it available values from dataset/query in the same report. This is where I am guessing what I want may not be possible. When I select my Location(s), then run the report it all looks good. However, when I click on one of the Expand/Collapse text boxes, it clears out the values that I selected for the location(s). I am guessing this is due to the fact that the available values for the Location parameter is set via a query at run time. Is there any way to maintain the values for the Location parameter when triggering the expand/collapse buttons?
Thanks in advance!

SSRS: How To Create Dynamic Report With Multiple Subreports?

I am still fairly new to SSRS, and I do not know what I need to/can provide as examples to help clarify my issue.
I am developing an SSRS report that accesses a NAV database and generates a report for an equipment number. My task is to generate a master report that can print multiple of those kind of reports(currently 10 max). I am using sub-reports to get the content that I need for an equipment number.
I am looking for a way to make this dynamic, where I can generate 1 to n sub-reports based on how many values were picked for the multi-value parameter. The end result should be one PDF file that contains the full report for each equipment number listed. I am trying to only use SSRS.
I have seen where I could hide sub-reports then make them visible if a condition is met, but this isn't the functionality that I am looking to use. So, what would be the best way to dynamically generate sub-reports based on a multi-value parameter?
I figured it out. I made the sub-report parameter equal no value. I made the main report with a parameter that can select multiple equipment numbers, a list, and a data set which filtered down to the appropriate equipment numbers to avoid duplication. I made the sub-report object in the main take in the cell value from the list equipment number. When the list proceeded to the next row, it copied all of the objects in the box area.

How do I pass the same parameter to multiple Command statements in Crystal Reports XI?

My DB does not have the tables I need, so I have to create custom SQL queries (commands in Crystal terminology), embed the results in a subreport, and fill my report with subreports. Here's what I want to happen:
Report asks user for a date
That date gets passed into the subreports
The date passed into subreports gets used in the query.
User only has to enter date once, everything else happens behind the scenes
Here's what actually happens:
User is asked for date for subreport 1
User is asked for date for subreport 2
etc etc
User gets frustrated and report is unsuccessful.
I know I can link parameter fields between reports, but as I understand it, I cannot do the same with commands. How can I rectify this?
Right-click on the subreport object and choose Change SubReport Links,
then select how the parameter is to be used by the subreport.
Courtesy: #MartW
I was wrong about the links not working. They do work, with modification.
As long as your queries are using parameters named the same way, this can work. With the default linking, you'll get a parameter window that looks like this: https://imgur.com/LF3PffB. If you modify your linking to look like this: https://imgur.com/t0HpMEC, then the reportingDate parameter used in the main report will be passed into the individual SQL queries of the subreports, as expected. Thanks to Nepali for pushing me in the right direction!

Get concrete value in Pentaho Report Designer

Let me explain my problem,
in Pentaho Report Designer I want to build such a report, where I have one data set, i.e. one request to database
SELECT code, name FROM EMPLOYEES
and show result of this request not in the form of list, but put every result in appropriate place. i.e. like in below picture
Where field "code" is unique, just one result can be put into red label in picture.
How can I do this in Pentaho Report Designer?
I can solve this problem by creating 3 data set, for each of caption. But what if captions like this will be much more, creating requests for each of this caption will not be so effective.
Hope I could explain my question.
I don't know if I got it right, but If you want to use the values returned by your query, you could create a new formula called "your_formula":
=MULTIVALUEQUERY("name_of_your_query")
This will give you an array with the result of the query. Then you could use another formula to get the 1st result of the array. For example:
=ARRAYLEFT([your_formula])
and get the first result of your query. This way let you use your_formula as parameter. This means you can drag and drop it on your report and use it.
I hope it helps.
Regards,
Tatan.

Issue related to the parameter of report in Pentaho Report Designer

I have a chart that contains 4 parameters and every parameter is related to the following one, i success i having the result of the chart by selecting the whole parameters one after the other,
The probleme is that i want to have another option by having the result of the chart by selecting also just one parameter or having the result without selecting any parameter
Can you please help me as soon as possible
Thanks a lot
There is one checkbox available while creating a parameter "Mandatory".Just remove the Right click from the checkboxes while creating all four parameters.Now you can check your result while selecting any parameter you want.