Jasper Report - Sort Report Content By Report Variable

Monday, June 23, 2014 Unknown 1 Comments



In here I’m using

Product Version: Jaspersoft iReport Designer Professional 5.0.0
Java                    : 1.6.0_45
System               : Windows 7

First create jasper report variable, in this example it is Expenditure_order.
According to my requirement it is type of String and calculation nothing and Reset type Report.


After that we need to define variable expression for sorting.

In my case there are 3 expenditure types. Let’s say Recurrent, Public Debt and Capital.
So I need to sort this as Recurrent, Capital and Public Debt.
When I use Ascending order it return Capital, Public Debt and Recurrent.
When I use Descending order it return Recurrent, Public Debt and Capital.
So I’m not able to use Ascending or Descending order for these criteria.
So I have used variable expression for change the sort order.
Now click on ok button and then we have a sorted variable.


Then move to the jasper report query window using this icon.


In Query window there is a button called Sort options.


Click on Sort options button and then you can get Sorting window.
In here we can add sort field in to the report.
Click on Add field button the and then you can get Add/Modify parameter window.


In Add/Modify parameter window, you can select sort by variable,
According to the example it is Expenditure_order and you can define sort type also.
Then click on ok button


So now we add the sorting variable successfully.
If you need you can remove or modify the sorting variable.
Also you can add more than one variable if you required.
Click on close button to exit.


Click on button to exit from query window.


After this report content ordered according to requirement (Recurrent, Capital and Public Debt). 

1 comments:

Jasper Report - Return Sub Report Variable Value in to Main Report

Monday, June 02, 2014 Unknown 7 Comments


In here I’m using

Product Version: Jaspersoft iReport Designer Professional 5.0.0
Java                    : 1.6.0_45
System                  : Windows 7

First you need to create a variable inside your sub report
In this example I have created the variable called SUB_Rec_Year_2_249 as Big decimal.
And get Sum of the Variable expression value with reset type of Report

Then In your Main report, create variable with Name and Type. In this example it is GET_SUB_Rec_Year_2_249 as Big decimal.
So this variable calculation type should be System and also reset type should be None.
So the select the sub report that imported to the main report and view the properties. In the properties , you can find Return values 
Then click on Return value icon, and then you can see the set of return values from sub report in to main report. But initially it not display anything, After you setting the return values it display the Sub report Variable (A variable from sub report) and Destination Variable(Variable name inside main report)



In this Return value window, click on Add button then it display the Sub report and Main report variable mapping window. This window contains two drop down boxes, sub report variable and local destination variable.
In this sub report dropdown list normally not display the variable names that we created. So please copy the exact variable name from sub report the paste here. According to the example this sub report variable name should be SUB_Rec_Year_2_249. Then local destination variable drop down, select the variable that we created to get return value from sub report. According to the example this local destination variable name should be GET_SUB_Rec_Year_2_249. Calculation type is Nothing and click on Ok button.

Then you can see this sub report and main report variable mapping added in to the return values mapping list. In here you can modify or delete the variable mapping if you needed.

So now you can get the sub report variable value using the main report variable.
In practical scenario, You can get this return values below the sub report inclusion

7 comments: