Jump to content
We've recently updated our Privacy Statement, available here ×

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


msavage_1

Recommended Posts

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. 
if(_prnt.getPages().size()==0){ 
//redirect to std page 

jasperPrint.getPages().isEmpty()

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

 

EXAMPLE:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport 
    xmlns="http://jasperreports.sourceforge.net/jasperreports" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd
    name="POLA-Wharfage-Container" 
    language="groovy" 
    whenNoDataType="NoPages"
    pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" 
    uuid="e0269380-8eae-4dcf-b533-73344ccbfcd3">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...