I am trying to execute the whole content when the parameter is null and conditional executional execution if the parameter is given a value. The whole content is executing but the conditional execution is not working.
The code which I tried is
<parameter name="Application" class="java.lang.String">
<parameterDescription><![CDATA[Application Name]]></parameterDescription>
</parameter>
<parameter name="whereClause" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{Application} == null || $P{Application}.isEmpty() ?
"1=1" : "((dt>= TO_TIMESTAMP($P{FromDtQry}, 'yyyy-MM-dd HH24:MI:ss') AND dt<=
TO_TIMESTAMP($P{ToDtQry}, 'yyyy-MM-dd HH24:MI:ss')) AND (rv202=" + $P{Application} + ")"
]]>
</defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT id,dt,estz,evt,voc,rv201,rv202,rv203,rv204,rv205,rv40
FROM idmrpt_cefevents_v
WHERE
$P!{whereClause}]]>
</queryString>
Could anyone help me out with this?
Related
I am generating a report having a table and a Line graph.
The master report dataset returns 8 records. So, I need 8 pages with each page displaying data for each record. I have mapped the field from master dataset to both the table and line graph's dataset.
The table is displayed 8 times perfectly with the correct param value.
But, the line graph always shows data for the last parameter value.
Jrxml Content:
<?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="chart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="66962ca4-5579-453f-a9fe-5d7284566dc1">
<subDataset name="chartDS" uuid="74b2bdf1-5e99-43ec-94c6-f6c999ea449c">
<parameter name="deviceId" class="java.lang.Long"/>
<queryString language="SQL">
<![CDATA[SELECT
ticket.descr,
IFNULL(SUM(diff)/60, 0) as duration,
DATE(ticket.created_date) as date
FROM
(SELECT
t.id, t.created_date, t.restored_date, E.descr,TIMESTAMPDIFF(SECOND,t.created_date,t.restored_date) as diff
FROM
ticket t
Inner JOIN (SELECT DISTINCT
description AS descr
FROM
alarm_config
WHERE
enabled = 1
AND site_location_device_id = $P{deviceId} ) E ON t.description LIKE CONCAT('%', E.descr, '%')
AND t.site_location_device_id = $P{deviceId}
ORDER BY E.descr) ticket
GROUP BY ticket.descr, DATE(ticket.created_date)
ORDER BY DATE(ticket.created_date)]]>
</queryString>
<field name="descr" class="java.lang.String"/>
<field name="duration" class="java.math.BigDecimal"/>
<field name="date" class="java.sql.Date"/>
</subDataset>
<queryString language="SQL">
<![CDATA[SELECT
sl.location_name,sld.id as deviceId ,sld.name
FROM
site
INNER JOIN
site_location sl ON site.id = sl.site_id
INNER JOIN
site_location_device sld ON sl.id = sld.site_location_id
where site_id = 32 and sld.device_type_id = (SELECT id FROM device_type WHERE name LIKE 'HSS')
]]>
</queryString>
<field name="location_name" class="java.lang.String"/>
<field name="deviceId" class="java.lang.Long"/>
<field name="name" class="java.lang.String"/>
<detail>
<band height="273" splitType="Stretch">
<barChart>
<chart evaluationTime="Report">
<reportElement x="20" y="23" width="514" height="200" uuid="53f820c6-7e46-4052-bcdf-65d3a4b9cf15"/>
<chartTitle>
<titleExpression><![CDATA[$F{deviceId}]]></titleExpression>
</chartTitle>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="chartDS" uuid="94e17f1e-b5a7-4b22-9864-481fc0adf56b">
<datasetParameter name="deviceId">
<datasetParameterExpression><![CDATA[$F{deviceId}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA[$F{descr}]]></seriesExpression>
<categoryExpression><![CDATA[$F{date}]]></categoryExpression>
<valueExpression><![CDATA[$F{duration}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot labelRotation="54.0"/>
<itemLabel/>
<categoryAxisFormat labelRotation="54.0">
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</barPlot>
</barChart>
</band>
</detail>
</jasperReport>
PS: Both table and graph are in the detail section.
Also, I am trying this from eclipse - report designer plugin
Finally, I managed to solve the problem.
The issue was with the evaluation time of the chart's expression.
It was by mistake set to "Report".I changed it to "Now".
Replaced this
<chart evaluationTime="Report">
with below
<chart evaluationTime="Now">
evaluationTime − Determines when the chart's expression will be evaluated. Values could be Now, Report, Page, Column, Group, Band. The default value is Now
This question already has answers here:
formatting a string to a currency format in jasper report
(8 answers)
Closed 7 years ago.
I need to print two numbers in the same row with spaces or commas as
442233378,556664446 in this way I need to print using jasper reports.I am using the variable as $F(alias_name) to print these numbers.But it is printing out of the page as shown in the image it has to print the number above the line where the first number is printed.Please help me.
I think you get get a solution for this by just changing your query.
I have added a GROUP_CONCAT function onto your alias_name field, you can read more on what this does here.
SELECT
GROUP_CONCAT(DISTINCT alias_name SEPARATOR ', ') AS alias_name
FROM
service_alias
WHERE
service_id IN
(
SELECT
id
FROM
service
WHERE
order_id IN
(
SELECT
id
FROM
purchase_order
WHERE
id IN
(
SELECT
order_id
FROM
order_process
WHERE
invoice_id = $P{invoiceId}
)
AND
period_id != 1
)
)
Here is the query added into the entityDetails.jrxml file:
<?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="Entity details" pageWidth="595" pageHeight="875" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" >
<property name="com.jasperassistant.designer.GridHeight" value="12"/>
<property name="com.jasperassistant.designer.GridWidth" value="12"/>
<property name="com.jasperassistant.designer.SnapToGrid" value="false"/>
<property name="com.jasperassistant.designer.Grid" value="false"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="invoiceId" class="java.lang.Integer"/>
<queryString>
<![CDATA[
SELECT
GROUP_CONCAT(DISTINCT alias_name SEPARATOR ', ') AS alias_name
FROM
service_alias
WHERE
service_id IN
(
SELECT
id
FROM
service
WHERE
order_id IN
(
SELECT
id
FROM
purchase_order
WHERE
id IN
(
SELECT
order_id
FROM
order_process
WHERE
invoice_id = $P{invoiceId}
)
AND
period_id!=1
)
)
]]>
</queryString>
<field name="alias_name" class="java.lang.String"/>
<title>
<band splitType="Stretch"/>
</title>
<detail>
<band height="62">
<textField isBlankWhenNull="true">
<reportElement x="50" y="5" width="197" height="15" />
<textElement>
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{alias_name}]]></textFieldExpression>
</textField>
<image>
<reportElement x="18" y="4" width="18" height="13" />
<imageExpression><![CDATA["/opt/apps/openbrm-2.0/openbrm/resources/logos/phone-symbol.png"]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>
How to compare dates in JasperReports?
I want to use the "image Expression". I tried but thats not working
$P{current_date} <= $P{image_date} ? '1.jpg' : '2.jpg'
$P{current_date}.after($P{image_date}) ? '1.jpg' : '2.jpg'
new Long($P{current_date}.getTime()) <= new Long($P{image_date}.getTime()) ? '1.jpg' : '2.jpg'
If you have these parameters class="java.util.Date"
<parameter name="current_date" class="java.util.Date" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.util.Date()]]></defaultValueExpression>
</parameter>
<parameter name="image_date" class="java.util.Date">
<defaultValueExpression><![CDATA[new java.util.Date()]]></defaultValueExpression>
</parameter>
This image expression will work
<image>
<reportElement x="139" y="13" width="223" height="93" uuid="fdb46643-77b6-4d23-a88c-7108b97c091f"/>
<imageExpression><![CDATA[$P{current_date}.after($P{image_date}) ? "Full absolute path\\1.jpg" :"Full absolute path\\2.jpg"]]></imageExpression>
</image>
I think that your problem is merly that you are giving relative path of image to jasper report... you need to give absolute path to jasper report es. "C:\\Users\\Friberg\\Pictures\\1.jpg"
I also see some single ' in your code you need to use the " to return the String value of your path.
Development note: the 2 \\ in the path is because \ is escape char in java
This question already has answers here:
Stretch a row with data overflow while having multiple rows in a single band
(3 answers)
Closed 4 years ago.
I have fields in title and page header that have multiple lines. I want them to stretch vertically but the problem is the field below the stretched field is missing. I also grouped them using a frame.
The properties I set:
Position Type : Float
Stretch Type : Relative to Tallest Object
Stretch With Overflow : True
Please see below screen shot.
You can try these properties of text : -
For first field (Cashier Name) of title band use this properties :-
Position Type- Fix Relative to Top
Stretch Type- Relative to Band Height
Stretch With Overflow - true
For the second field (Date) set these properties
Position Type- Fix Relative to Bottom
Stretch Type- No stretch
Stretch With Overflow- false
In this report you can see the properties if you run the report with Sample HSQL database in ireport :-
<?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="ward utilization" pageWidth="300" pageHeight="300" orientation="Landscape" columnWidth="280" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10" uuid="85476864-df43-454c-83dd-9c1b475ec223">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from orders]]>
</queryString>
<field name="ORDERID" class="java.lang.Integer"/>
<field name="CUSTOMERID" class="java.lang.String"/>
<field name="EMPLOYEEID" class="java.lang.Integer"/>
<field name="ORDERDATE" class="java.sql.Timestamp"/>
<field name="REQUIREDDATE" class="java.sql.Timestamp"/>
<field name="SHIPPEDDATE" class="java.sql.Timestamp"/>
<field name="SHIPVIA" class="java.lang.Integer"/>
<field name="FREIGHT" class="java.math.BigDecimal"/>
<field name="SHIPNAME" class="java.lang.String"/>
<field name="SHIPADDRESS" class="java.lang.String"/>
<field name="SHIPCITY" class="java.lang.String"/>
<field name="SHIPREGION" class="java.lang.String"/>
<field name="SHIPPOSTALCODE" class="java.lang.String"/>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<group name="bed"/>
<title>
<band height="42">
<textField isStretchWithOverflow="true">
<reportElement uuid="c438eefe-5415-409e-8e7c-c763a7305ae2" stretchType="RelativeToBandHeight" x="87" y="0" width="24" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SHIPNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="83c8a0d7-af5f-43ec-88dd-7d923a5b2a28" positionType="FixRelativeToBottom" x="87" y="21" width="24" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SHIPCITY}]]></textFieldExpression>
</textField>
</band>
</title>
I see two possible solutions here.
based on tests reproducing your error, you can set the date field as float also and it will shift down as the previous label (cashier name) overflows. Unfortunately this is part of a solution because then the field date does not align with its label.
create a table and set those labels and fields as a table and let it handle the overflow naturally. I failed to test it without using a datasource but I'm sure you can pass it the current report's datasource and fetch the data you need from it and display that info on that table.
Let me know if it worked for you. Also, tell me what else did you try. I'm curious now :)
Good luck.
Stretch Type : Relative to Tallest Object make verttical size of any items as maximal from all items. In this case previous element overlaps next (missing) item.
This is not need. Set stretch type = "No stretch". "Stretch with overflow = true" is enough for correct display items. (imho)
Solution: Put each pair label:field into individual frame. In this case label-fields will display in the corresponding rows
Let me depict a situation: I have a report A and subreports B and C. A uses B and B uses C. Default value of SUBREPORT_DIR in A is $P{CUSTOM_SUBREPORT_DIR}. In A.jrxml I see:
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{CUSTOM_SUBREPORT_DIR}]]></defaultValueExpression>
</parameter>
<parameter name="CUSTOM_SUBREPORT_DIR" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
I also need a proper value of SUBREPORT_DIR in B so I passed it using iReport (Subreport properties/Parameters) so in A.jrxml I have:
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
And when I'm trying to generate report A I get net.sf.jasperreports.engine.JRException: Incompatible java.lang.Integer value assigned to parameter SUBREPORT_DIR in the B dataset.
I'm sure that $P{SUBREPORT_DIR} isn't an integer and type of SUBREPORT_DIR parameter in B subreport is String. All reports I made using iReport 4.0.2.
You can try the following (I do it in this way and it works):
Define the parameters in report A:
<parameter name="SUBREPORT_B_DIR" class="java.lang.String" isForPrompting="false" />
<parameter name="SUBREPORT_C_DIR" class="java.lang.String" isForPrompting="false" />
Define subreport B in report A. Here I use DataSource for report B from parameter. Also I send a parameter to subreport B with the subreport C directory and another parameter with DataSource for report C.
<subreport>
<reportElement x="0" y="16" width="583" height="10" />
<subreportParameter name="SUBREPORT_C_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_C_DIR}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="SubReportCDataSource">
<subreportParameterExpression><![CDATA[$P{SubReportCDataSource}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{SubReportBDataSource}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_B_DIR} + "B.jasper"]]></subreportExpression>
</subreport>
Finally, in subreport B, define subreport C:
<subreport>
<reportElement x="0" y="16" width="583" height="10" />
<dataSourceExpression><![CDATA[$P{SubReportCDataSource}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_C_DIR} + "C.jasper"]]></subreportExpression>
</subreport>