0

I want to access a VARIABLE from a JasperReports in my Java code. More specifically, I need to know the REPORT_COUNT and the SUBREPORT_COUNT in my Java code after filling the report. I've tried setting it as a property, but that doesn't work.

The report is scheduled, and I do not want to send the email if there is no data. I've tried setting the "When No Data" to "print 0 pages," and then checking the page count in the java code. This doesn't work if there is data in just the main or the just the subreport. I want it to print 0 pages if either the main or the subreports have no data.

I'm sure this has been asked, but I can't find exactly what I need. If someone could point me in the right direction, it would be appreciated.

2 Answers 2

2

Try the following:

JasperReport jasperReport = (JasperReport) JRLoader.loadObject("path/to/your.jasper");

// prior to version 4.6.0, you should use JRFiller.createFiller(jasperReport)
JRFiller.createFiller(DefaultJasperReportsContext.getInstance(), jasperReport);

JasperPrint print = filler.fill(yourParameterMap, yourDatasource);

Object value = filler.getVariableValue(variableName); // here's what you need

Be advised that you won't be able to use JasperFillManager.fillReport anymore.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! That is exactly what I needed. I didn't know about the JRFiller.
The JRFiller.createFiller(jasperReport) is deprecated consider modifying your answer JRFiller.createFiller(DefaultJasperReportsContext.getInstance(),jasperReport);, cheers.
0

@brunobastosg This won't work if we have reports that return one row with all null fields and 0 in data_found, in this case, you can't tell if it's really no data or not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.