Jasper Page break on New Field/Variable - jasper-reports

I am working on a jasper report, and I am trying to figure out a way for the report to page break on a variable change. The variable is actually a Field, and I put the value of the field in a variable.
Now, the Jasper Reports website has an example on how to break it by count like this
<groupExpression><![CDATA[new Boolean($V{BreakGroup_COUNT}.intValue()
> 5)]] ></groupExpression>
However, I am not sure of any way to compare the previous or next value and breaking after that.

You just want the report to start a new page when $F{MyField} changes value.
In this case simply create a group with 'Group Expression': $F{MyField}
Tick the option 'Start on a new page' for the group. There is no need for a variable.

Select the header of the group in the Document Structure window, and then select in the Properties window Start on New Page.

Related

Mark Report everytime it prints (preview) in JasperSoft iReport

Is it possible to mark a report based on the times we click Preview?
For example, if we preview the report once, it will show 1.
If we preview the report twice, it will show 2.
I am using Adempiere and would like to put the report inside the window. So, when I click 'Print' once, it will show 1, the same when I click Print for the second time it will show 2, etc.
Any suggestion will be useful :)
There is a field in the AD_Process table called Statistic_Count which function is to store how many times the process has been run.
What I would do is to pass the value of that field as a parameter to the report, so you can print it.
In the process parameter you could add a new numeric parameter called PreviewTimes and in the DefaultValue field set something like:
#SQL=SELECT statistic_count FROM AD_Process WHERE AD_Process_ID = #AD_Process_ID#
Then, in the Jasper Report you receive that number and include it.
Hope it helps.

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.

How to add page break

I am using JasperReports applied to my web application
I wanna put new page every time my date filed $F{date} change
I already tried drag break element with page break option from palette of iReport and drop it onto filed ->($F{date})
But nothing happened
please give me any advise or solution
Create two variables (in this order):
1. var_date_prev = $V{var_date}
2. var_date = $F{date}
Varibles are evaluated in order in which they are declared so var_date_prev will have date value from previous row.
Add property net.sf.jasperreports.export.xls.break.after.row on field after which you want to make page break and set the expression for the property
$V{var_date_prev} != null && $V{var_date_prev} != $V{var_date}

How to pass parameters in crosstab?

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.

Insert page breaks between report groups with two-sided printing

In group expert options I have set Keep Group Together, which makes sure a new page is set.
With two-sided printing enabled, how can I make sure that a new group always forms on a new sheet of paper? Can this be done in the formula expert? Is there some way of checking if the page I'm on is even or odd and insert a page from there? Just asking leading questions because I'm not familiar with what is possible with Crystal's formula editor. BTW, This is Crystal XI Enterprise Server.
You can do this with the onfirstrecord, pagenumber and the onlastrecord keywords.
On the group header section "New page before" formula...
not onfirstrecord //so every group (except the first) starts on a new page
On "New page after" formula...
//to keep the group from starting on even page but make sure the last page is not blank
remainder(pagenumber, 2) = 1 and not onlastrecord
Open the Section Expert screen. Select Report Header and check "Suppress (No Drill-Down)". Then select in the group header select the group you want to page break and check "New Page Before".
This Works fine if I need Page Break on one Group. How do I do if Page Break on Multiple Groups?
I found answer..
Using Next(Field) or Previous(Field), I added below condition and worked fine.
In Next Page Before formula:
Not onFirstRecord and ({table.field} <> previous({table.field}))
hi IronicMuffin i understand you question. the answer is versy simple but more effetcive.
step 1: Include dataset or database expert into your crystal report
Step2: In the outside surface of the report area right click and goto report and goto group expert
Step3: add the which field you include the group that time the bottom of the window options will appear
Step 4: click the option and agian goto 2nd tab of the option.
step 5: finally check(check=true) check box of Repeat Group header on each page other check box or put uncheck