Jump to content
Changes to the Jaspersoft community edition download ×

Dynamic variable expression calculation is not being displayed on the report.


deepakrsarangi
Go to solution Solved by reportdev,

Recommended Posts

Hi,

I have this unique problem of displaying variable value at runtime for each record basis.

The variable values should be calculated at runtime based on the parameter value provided. However the values are not getting rendered on the report.

 

I have already tried to set the variable "reset type to Page", still no success.

Here is the JRXML for the same. Please resolve.

 

Parameter JRXML:

<parameter name="PARAM_DYNAMIC1" class="java.lang.String">
<defaultValueExpression><![CDATA["IT_PM"]]></defaultValueExpression>
</parameter>
<parameter name="PARAM_DYNAMIC2" class="java.lang.String">
<defaultValueExpression><![CDATA["IT_PM"]]></defaultValueExpression>
</parameter>
 
Field JRXML:
 
<field name="ITPM" class="java.lang.String">
<fieldDescription><![CDATA[iTPM]]></fieldDescription>
</field>
<field name="ITPMOLEAD" class="java.lang.String">
<fieldDescription><![CDATA[iTPMOLEAD]]></fieldDescription>
</field>
<field name="BUSPMOLEAD" class="java.lang.String">
<fieldDescription><![CDATA[bUSPMOLEAD]]></fieldDescription>
</field>

Variable JRXML:

<variable name="Dynamic1" class="java.lang.String">
<variableExpression><![CDATA[($P{PARAM_DYNAMIC1} == "IT_PMO" ? "IT PMO Lead" : 
($P{PARAM_DYNAMIC1} == "BUS_PMO" ? "Business PMO Lead" : 
($P{PARAM_DYNAMIC1} == "IT_PM" ? "IT Project Manager" : 
($P{PARAM_DYNAMIC1} == "IT_SPONSOR" ? "IT Sponsor" : "")
)
)
)]]></variableExpression>
<initialValueExpression><![CDATA[($P{PARAM_DYNAMIC1} == "IT_PMO" ? "IT PMO Lead" : 
($P{PARAM_DYNAMIC1} == "BUS_PMO" ? "Business PMO Lead" : 
($P{PARAM_DYNAMIC1} == "IT_PM" ? "IT Project Manager" : 
($P{PARAM_DYNAMIC1} == "IT_SPONSOR" ? "IT Sponsor" : "")
)
)
)]]></initialValueExpression>
</variable>
<variable name="Dynamic2" class="java.lang.String">
<variableExpression><![CDATA[($P{PARAM_DYNAMIC1} == "IT_PMO" ? "IT PMO Lead" : 
($P{PARAM_DYNAMIC1} == "BUS_PMO" ? "Business PMO Lead" : 
($P{PARAM_DYNAMIC1} == "IT_PM" ? "IT Project Manager" : 
($P{PARAM_DYNAMIC1} == "IT_SPONSOR" ? "IT Sponsor" : "")
)
)
)]]></variableExpression>
<initialValueExpression><![CDATA[($P{PARAM_DYNAMIC1} == "IT_PMO" ? "IT PMO Lead" : 
($P{PARAM_DYNAMIC1} == "BUS_PMO" ? "Business PMO Lead" : 
($P{PARAM_DYNAMIC1} == "IT_PM" ? "IT Project Manager" : 
($P{PARAM_DYNAMIC1} == "IT_SPONSOR" ? "IT Sponsor" : "")
)
)
)]]></initialValueExpression>
</variable>
<variable name="Dynamic1_Val" class="java.lang.String">
<variableExpression><![CDATA[($V{Dynamic1} == "IT_PMO" ? ($F{ITPMOLEAD} == null ? "Nothing to display" : $F{ITPMOLEAD} ):
($V{Dynamic1} == "BUS_PMO" ? ($F{BUSPMOLEAD} == null ? "Nothing to display" : $F{BUSPMOLEAD} ):
($V{Dynamic1} == "IT_PM" ? ($F{ITPM} == null ? "Nothing to display" : $F{ITPM} ):
($V{Dynamic1} == "IT_SPONSOR" ? ($F{ITSPONSOR} == null ? "Nothing to display" : $F{ITSPONSOR} ) : "")
)
)
)]]></variableExpression>
</variable>
<variable name="Dynamic2_Val" class="java.lang.String">
<variableExpression><![CDATA[($V{Dynamic2} == "IT_PMO" ? ($F{ITPMOLEAD} == null ? "Nothing to display" : $F{ITPMOLEAD} ):
($V{Dynamic2} == "BUS_PMO" ? ($F{BUSPMOLEAD} == null ? "Nothing to display" : $F{BUSPMOLEAD} ):
($V{Dynamic2} == "IT_PM" ? ($F{ITPM} == null ? "Nothing to display" : $F{ITPM} ):
($V{Dynamic2} == "IT_SPONSOR" ? ($F{ITSPONSOR} == null ? "Nothing to display" : $F{ITSPONSOR} ) : "")
)
)
)]]></variableExpression>
</variable>
 
Text field JRXML:
 
<textField evaluationTime="Page">
<reportElement x="102" y="59" width="121" height="17" uuid="46801896-fe76-418d-8ec8-e672bccfd86c"/>
<textElement verticalAlignment="Bottom">
<font fontName="VoyaArial" size="9"/>
</textElement>
<textFieldExpression><![CDATA[$V{Dynamic1_Val}]]></textFieldExpression>
</textField>
<textField evaluationTime="Page">
<reportElement x="102" y="75" width="121" height="17" uuid="46801896-fe76-418d-8ec8-e672bccfd86c"/>
<textElement verticalAlignment="Bottom">
<font fontName="VoyaArial" size="9"/>
</textElement>
<textFieldExpression><![CDATA[$V{Dynamic2_Val}]]></textFieldExpression>
</textField>
 
 
The text fields are not getting rendered for any parameter value specified.
Any help would be much appreciated.
 
Thanks.

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  --><!-- 2017-02-15T14:59:49 --><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="variable" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="68d0c2e9-bd2c-476f-a817-ed72542eac63">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>    <parameter name="PARAM_DYNAMIC1" class="java.lang.String">        <defaultValueExpression><![CDATA["IT_PM"]]></defaultValueExpression>    </parameter>    <parameter name="PARAM_DYNAMIC2" class="java.lang.String">        <defaultValueExpression><![CDATA["IT_PM"]]></defaultValueExpression>    </parameter>    <queryString>        <![CDATA[select 'ITPM' as ITPM,'ITPMOLEAD' as ITPMOLEAD,'BUSPMOLEAD' as BUSPMOLEAD,'ITSPONSOR' as ITSPONSOR from dual]]>    </queryString>    <field name="ITPM" class="java.lang.String"/>    <field name="ITPMOLEAD" class="java.lang.String"/>    <field name="BUSPMOLEAD" class="java.lang.String"/>    <field name="ITSPONSOR" class="java.lang.String"/>    <variable name="Dynamic1" class="java.lang.String" resetType="Master">        <variableExpression><![CDATA[($P{PARAM_DYNAMIC1}.equals("IT_PMO") ? "IT PMO Lead" :($P{PARAM_DYNAMIC1}.equals("BUS_PMO") ? "Business PMO Lead" :($P{PARAM_DYNAMIC1}.equals("IT_PM") ? "IT Project Manager" :($P{PARAM_DYNAMIC1}.equals("IT_SPONSOR")? "IT Sponsor" : ""))))]]></variableExpression>    </variable>    <variable name="Dynamic2" class="java.lang.String" resetType="Master">        <variableExpression><![CDATA[($P{PARAM_DYNAMIC1}.equals("IT_PMO") ? "IT PMO Lead" :($P{PARAM_DYNAMIC1}.equals("BUS_PMO") ? "Business PMO Lead" :($P{PARAM_DYNAMIC1}.equals("IT_PM") ? "IT Project Manager" :($P{PARAM_DYNAMIC1}.equals("IT_SPONSOR")? "IT Sponsor" : ""))))]]></variableExpression>    </variable>    <variable name="Dynamic1_Val" class="java.lang.String">        <variableExpression><![CDATA[($V{Dynamic1} == "IT PMO Lead" ? ($F{ITPMOLEAD} == null ? "Nothing to display" : $F{ITPMOLEAD} ):($V{Dynamic1} == "Business PMO Lead" ? ($F{BUSPMOLEAD} == null ? "Nothing to display" : $F{BUSPMOLEAD} ):($V{Dynamic1} == "IT Project Manager" ? ($F{ITPM} == null ? "Nothing to display" : $F{ITPM} ):($V{Dynamic1} == "IT Sponsor" ? ($F{ITSPONSOR} == null ? "Nothing to display" : $F{ITSPONSOR} ) : ""))))]]></variableExpression>    </variable>    <variable name="Dynamic2_Val" class="java.lang.String">        <variableExpression><![CDATA[($V{Dynamic2} == "IT PMO Lead" ? ($F{ITPMOLEAD} == null ? "Nothing to display" : $F{ITPMOLEAD} ):($V{Dynamic2} == "Business PMO Lead" ? ($F{BUSPMOLEAD} == null ? "Nothing to display" : $F{BUSPMOLEAD} ):($V{Dynamic2} == "IT Project Manager" ? ($F{ITPM} == null ? "Nothing to display" : $F{ITPM} ):($V{Dynamic2} == "IT Sponsor" ? ($F{ITSPONSOR} == null ? "Nothing to display" : $F{ITSPONSOR} ) : ""))))]]></variableExpression>    </variable>    <background>        <band splitType="Stretch"/>    </background>    <title>        <band height="30" splitType="Stretch">            <textField evaluationTime="Report">                <reportElement x="0" y="0" width="100" height="30" uuid="7ef8763d-4294-4a5f-b615-7013a4b061d6"/>                <textFieldExpression><![CDATA[$V{Dynamic1_Val}]]></textFieldExpression>            </textField>            <textField evaluationTime="Report">                <reportElement x="180" y="0" width="100" height="30" uuid="1ca2c1d6-b941-418a-bfd3-0c34e36751fd"/>                <textFieldExpression><![CDATA[$V{Dynamic2_Val}]]></textFieldExpression>            </textField>        </band>    </title>    <pageHeader>        <band height="35" splitType="Stretch"/>    </pageHeader>    <columnHeader>        <band height="61" splitType="Stretch"/>    </columnHeader>    <detail>        <band height="30" splitType="Stretch"/>    </detail>    <columnFooter>        <band height="45" splitType="Stretch"/>    </columnFooter>    <pageFooter>        <band height="56" splitType="Stretch"/>    </pageFooter>    <summary>        <band height="42" splitType="Stretch"/>    </summary></jasperReport>[/code]

I believe that your conditional expressions are not correct. check the above jrxml

 

PARAM_DYNAMIC1 parameter is returning "IT_PM"

Dynamic1 variable is decoding "IT_PM" and returning "IT Project Manager"

Dynamic1_Val variable is again trying to decode the value of Dynamic1 variable as "IT_PM" , which is not correct. It should be looking for "IT Project Manager".

Link to comment
Share on other sites

Thanks. Let me clear out any confusion here.

I am displaying both Dynamic1 and Dynamic1_Val. The following conditions are being calculated for each record retrived from DB.

If Param_Dynamic1 = "IT_PM, then Dynamic1 = "IT Project Manager", Text Field1.text = "IT Project Manager" (Value of Dynamic1)

If Dynamic1= "IT Project Manager", then Dynamic1_Val = Query Field {IT_PM}, Text Field2.text = IT PM Value from DB (Value of Dynamic1_Val)

 

The problem is that, not a single text field value is being displayed on the report.

 

To your point: I agree that calculation of Dynamic1_Val is wrong. I will rectify that. But why Dynamic1 variable value is not displayed on the report even.

Link to comment
Share on other sites

  • Solution

Try using the above posted jrxml and display the Dynamic1 variable with the evaluation time of Report.

It is displaying the value after it has been fixed.

 

"==" has been used for checking equality of objects, which will not work in some of the cases.

I have changed it to ".equals" method which is specifically used for checking equality of objects

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...