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

0

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>
 

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

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?

sthomas_3 - 4 weeks 7 hours ago

1 Answer:

0

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

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