How do I stop report output if no data is returned?


I have been looking at the answers for the past two+ hours and I see some ideas but no sample code.  I'm very new to Jasper Reports so as much detail you can provide the better.

I have an autometed scheduler running everyday at 8am to run a report.  Most days the query returns zero rows so I do not want the report to be created/emailed.

I tried adding the whenNoDataType="NoPages" but that did not work. (see example below)

In reading through the questions and answers it seems I must also add something like this...

JasperPrint _prnt = JasperManager.fillReport( _rep, params, conn); 

//check for pages here.--no pages helps here. 
//redirect to std page 


But this is pretty foreign to me.  Can you provide me an example of where in the jrxml I would put the above text?  


I appreciate the help



<?xml version="1.0" encoding="UTF-8"?>
    pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" 
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>

msavage_1's picture
Joined: May 20 2019 - 3:13pm
Last seen: 3 weeks 3 days ago


While scheduling the report in Jasperreports server , In the Notification tab you will find an option 

 'Do not send emails for empty reports'

This property available in scheduler has two requirements: report query should not return any values, and whenNoDataType property should be set to 'No Pages'

Did you try this option out?

sthomas_3 - 4 weeks 7 hours ago

1 Answer:


Your code snippets you've found are plain JAVA code and not for integration into the jrxml-design. 

So if you run your report manually with API functions of JasperReports (e.g. the common steps: load design, set parameters, fill design, print/mail/export filled report result), then you could use these snippets to check whether the resulting JasperPrint Object contains pages at all and then you could prevent your mail delivery in your code.

If you use JasperServer, then the comment above by sthomas_03 would be the solution.

hth + regards


C-Box's picture
Joined: Jul 19 2006 - 5:58pm
Last seen: 21 hours 4 min ago