How to evaluate variable when there is no data?

0

My report is using a parameter to determine the report title. It is displaying null when there is no data.  I've tried changing the variable $V{reportName} Evaluation Time, but no luck.  Can anybody help me?

Thanks.

PS: It is using mssql data adapter and the current querystring does not return any row.  To return rows, change 2=1 to 1=1.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 5.6.1.final using JasperReports Library version 5.6.1  -->
<!-- 2017-05-01T15:39:40 -->
<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="Evaluate" pageWidth="595" pageHeight="842" 
              whenNoDataType="AllSectionsNoDetail" columnWidth="555" 
              leftMargin="20" rightMargin="20" topMargin="20" 
              bottomMargin="20" uuid="a736ce53-7e76-4194-9086-96d2270a6250">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="SQLEXPRESSR2"/>
    <parameter name="ReportType" class="java.lang.String">
        <defaultValueExpression><![CDATA["A"]]></defaultValueExpression>
    </parameter>
    <queryString language="SQL">
        <![CDATA[select Col1 from (values (1),(2)) as a(Col1) where 2=1]]>
    </queryString>
    <field name="Col1" class="java.lang.Integer"/>
    <variable name="ReportName" class="java.lang.String">
        <variableExpression><![CDATA[$P{ReportType}.equals("A")? $V{reportTitleA}:$V{reportTitleB}]]></variableExpression>
    </variable>
    <variable name="reportTitleA" class="java.lang.String">
        <variableExpression><![CDATA["Report A"]]></variableExpression>
    </variable>
    <variable name="reportTitleB" class="java.lang.String">
        <variableExpression><![CDATA["Report Other"]]></variableExpression>
    </variable>
    <pageHeader>
        <band height="22" splitType="Stretch">
            <textField evaluationTime="Report">
                <reportElement x="0" y="0" width="390" height="20" 
                               uuid="98c519b9-7350-4cd6-a71e-f2fb1c0e7b80"/>
                <textFieldExpression><![CDATA[$V{ReportName}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="14" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="15" splitType="Stretch">
            <property name="local_mesure_unitheight" value="pixel"/>
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <textField>
                <reportElement x="0" y="0" width="100" height="14" 
                               uuid="82ab5741-1138-4173-88f5-42ef07a6cb9f">
                    <property name="local_mesure_unitheight" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{Col1}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
quacker.2715's picture
Joined: Jan 12 2017 - 3:26pm
Last seen: 2 years 6 months ago

3 Answers:

0

Hi,

In order to be properly evaluated, the variable ReportName should be placed after reportTitleA and reportTitleB. You also need to set the initial value expressions for all variables:

    <variable name="reportTitleA" class="java.lang.String">
        <variableExpression><![CDATA["Report A"]]></variableExpression>
        <initialValueExpression><![CDATA["Report A"]]></initialValueExpression>
    </variable>
    <variable name="reportTitleB" class="java.lang.String">
        <variableExpression><![CDATA["Report Other"]]></variableExpression>
        <initialValueExpression><![CDATA["Report Other"]]></initialValueExpression>
    </variable>
    <variable name="ReportName" class="java.lang.String">
        <variableExpression><![CDATA[$P{ReportType}.equals("A")? $V{reportTitleA}:$V{reportTitleB}]]></variableExpression>
        <initialValueExpression><![CDATA[$P{ReportType}.equals("A")? $V{reportTitleA}:$V{reportTitleB}]]></initialValueExpression>
    </variable>

shertage's picture
1982
Joined: Sep 26 2006 - 8:06pm
Last seen: 1 day 14 hours ago
0

Use paramaters for this purpose instead. Is what I use.

Mariano

mlopez_1's picture
937
Joined: Oct 21 2013 - 8:08am
Last seen: 20 hours 20 min ago
0

its simply

nessrineselmi215's picture
Joined: May 3 2017 - 1:18am
Last seen: 2 years 9 months ago
Feedback