How to pass parameters in crosstab? - jasper-reports

Can anyone tell me, how to pass parameters to crosstab?

I use Jaspersoft Studio (5.6.2) for designing the reports.
select the crosstab, in the report it is placed. Then goto properties. Then select the tab Advanced. Here you can find the property -Parameters Map Expression-, as value you put what Stoian writes above: $P{REPORT_PARAMETERS_MAP}
Make sure you have a parameter created with the same name you want to use in the crosstab, in the report the crosstab is placed. Put nothing in the -Default Value Expression- if the value is comming from a parent subreport.
in the crosstab (by double clicking on it) goto the Outline. Here you find Parameters, I also created a parameter here with the same name, setting the -Default Value Expression- to the $P{ here you put the name of the parameter you used in point 2 }
seems to work

If you are using iReport or any other report designer, just embed the crosstab into the main report. If you click on the crosstab element and expand it, you will get to see the 'parameters' section. Right-click on the 'parameters' section to add a new parameter and name it accordingly. In the 'Value Expression' for that crosstab parameter, select the parameter from the main report (The report holding the crosstab). Voila!

Do just like bchetty says, just do not forget to add the parameterMapExpression in the crosstab properties of the crosstab. For Report parameters it should be $P{REPORT_PARAMETERS_MAP}

First Make the cross tab in an another report && import it into your main report. Now right click on the subreport you will get an option of change subreport links Where you can put your parameter field to pass in cross tab report.

Related

How to dynamically order subreports in main report(jasper report)

Suppose,One main report can have 9 sub-reports.
Then user can have UI from which user can order the sub-report according to his/her choice.(like,which sub-report should be displayed first and which is next and so on).
SO,how can i achieve this ?
Follow the below steps to achieve your requirements
Create 9 parameters say, reportpath1,reportpath2,reportpath3,....reportpath9.
Prompt user to enter the order of the reports. Based on the order pass the respected report path to every parameter.
Meaning, if subreport9 is selected as 1st report, then pass the path of that subreport9 as reportpath1, if subreport8 is selected as 2nd report, then pass the path of that report as reportpath2 and so on
For example, if path of subreport9 is "report/samples/subreports/subreport9", then set parameter reportpath1 value as "report/samples/subreports/subreport9". If path of subreport8 is "report/samples/subreports/subreport8", then set paramter reportpath2 value as "report/samples/subreports/subreport8" and so on.
In report design, create 9 subreport and instead of hard-coding the path of each report, pass parameter in subreportexpression as below
For subreport1,
<subreportExpression><![CDATA[$P{ReportPath1}]]></subreportExpression>
For subreport2,
<subreportExpression><![CDATA[$P{ReportPath2}]]></subreportExpression>
and so on.
Hope this should solve your problem.
Answer for getting variable from subreport
Right click on subreport in Parent report.
Go to Properties
Under Subreport session, click "Return values"
Add the subreport variable and map it to the parentreport variable.
Then use that parentreport variable in your parent report.
Hope this should solve your another problem.

Display Jasper report file name

I'm creating a jasper report using iReports 5.2.0 and I want to display the report file name in it.
Can't find any variable that has that information and I would like to get an alternative to pass it in the parameters.
How can I do it?
When you design your report, make a new PARAMETER named, for instance: NAME_REPORT.
After that, put a TextField in your report, for example, in your Title section, and
put as value of your TextField the parameter like a expression: $P{NAME_REPORT}
When you preview your report, ask you to give a value to this parameter and then, you see the title with the name
of your report file.
In your java code you will do somethink like that:
parameters.put("NAME_REPORT", "myreport.jrxml");
.....
JasperFillManager.fillReport(report, parameters, connection)
.....

Parameter Value in main report is not passed to a parameter in the subreport

I need your assistant in passing a value of a parameter in the main report to the subreport. I defined a parameter in the main report which is called {?ReportNumber} and its type is Number and it is static.
In the Select Expert of the Main Report I added the below code:
{engine.reportnumber}={?ReportNumber}
This will take the value of the reportnumber from the table and it will assign it to the parameter. Each time I ran the report, the value will be different based on the retrieved data.
In the Subreport, I created again a parameter with the same name {?ReportNumber} and its type is Number and it is static.
I have added a subreport link which is {?ReportNumber} parameter and below I selected to match the {?ReportNumber} parameter which is in the subreport.
However my issue is that when I ran the report, the report is prompting me to enter the parameter of the subreport, even though I have added and assigned a value to it as I have explained in the above steps.
I am using Crystal Reports 2011
Even tried to use shared variable in the main report:
shared numbervar report_number := {engine.rptno};
report_number;
In the sub report, I create a formula ("Shared_report_number") and I placed it in the report header. It has the code:
shared numbervar report_number;
report_number;
I clicked on Select Expert and then I chose the field {engine.rptno} is equal to {#Shared_report_number}, it produces an error that : the formula cannot be used because it must be evaluated later
Kindly assist me in passing the value of the parameter from the main report to the subreport.
This prompting shows that your parameter is not link properly.
When you link the parameter. In left side, main report parameter show
1. is of sp parameter
2. is of custom report parameter
While you linking, note that you custom report with report name is joined.
Please check this below link, in UI potion of third image , right-bottom side you have to choose sub-report parameter. So check and then link.
http://blog.niklasottosson.com/?p=1137
In your case, I think your main report parameter is link with itself. not with subreport parameter.
Check this link carefully while mapping.

How to pass the parameter from one subreport to another subreport

I am newbie and I'm designing my report using iReport 4.5.
I have a main report (MainReport) and three subreports (Sub1, Sub2, Sub3)
In Sub1 I have three summary variables say presentPayable, presentPayment, balance
In Sub2 I have one summary variable say totalCost
I need to use the summary variables of Sub1, Sub2 in my Sub3.
How can I do this? Is this possible to pass the variables from one subreport to another?
Otherwise please provide me any alternate to do this.
To pass a value from a subreport to its parent, the parent must first have a variable to receive the value. In your case the main report should have 4 variables, one each for presentPayable, presentPayment, balance, and totalCost.
Next you need to add a returnValue element to the subreport element in the main report. This element maps a variable in the subreport to a variable in this report using the attributes subreportVariable and toVariable.
To do this in iReport, click on your subreport element in the main report. In the properties list, click on Return Values. A dialog should appear. Click on the Add button. Type the name of the subreport variable and select the variable in this report that you would like it to be transferred to. You should leave the calculation type as "Nothing", which will instruct jasper to simply overwrite the variable with the new value. Click Ok to add this, then repeat for the other variables/subreports.
Now when you run the report, each time the subreport has completed processing, the current value of the variable in the subreport is passed back to the specified variable in the main report.
To use that value in another subreport, you need to pass the variable from the main report to the other subreport as a parameter. This has two parts: Adding a subreportParameter to the subreport element in the parent report, and adding a parameter to the subreport itself.
In iReport, click on your subreport element in the main report. In the properties list, click on Parameters. In the dialog that appears, click the Add button. Give the parameter a name (e.g. presentPayable) and input a value expression that references the variable in your main report (e.g. $V{presentPayable}). Repeat this for each of the variables that you want to pass in.
Next, open your subreport. In the report inspector, right-click on Parameters. Select Add Parameter, then rename the new parameter to match the name you entered in the previous step.
In the subreport, you should now be able to reference these values like any other parameter (e.g. $P{presentPayable}).

Subreport values are not displayed in main report

I have my main report which contains 1 subreport. When I run my main report the subreport values are not displayed in my main report, but when I run my subreport individually I can see the output in PDF format. Can anyone help me in fixing this issue?
First see the connection with right click on the report and click on open subreport if its working then clik on the subreport go to the subreport property and see the parameter passed to the subreport is correct or not if not please pass properly. also see the parameter value required for the subreport is that comming from main report.
Means : if your subreport require account_id = 5 the it must that main report passes the value 5 to the subreport.
You need to call the SubreportProcessingEventHandler and add the datasource.
Step 2: Check the properties of subreport.
If it does not need any parameters from main report. Do not add any.
The path of the repo