Jump to content

Can I show a band conditionally


robert.abed

Recommended Posts

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi, 

You can use "Print When Expression" to hide report bands. You have to get in a parameter of field if your query returns and empty set and set an expression as follows: 

$F{data} != null ? Boolean.TRUE : Boolean.FALSE

In this case, if the field "data" is null the band in which you set the expression will be hided, otherwise it will be shown. 

Hope this helps,

Regards

 

Link to comment
Share on other sites

Not sure if it is the best one, but a possible solution could be the following one: 

You create a Variable, which counts the number of elements you have in your query. For example, imagine that you retrieve the field "Fld" in your query. You can create a variable with the following properties: 

-  Name: NumRow

- Calculation: Count

- Variable Expression: $F{Fld}

This variable will calculate the number of rows you have in your query, if it is 0, it means there is not any row so you can hide the band. In the "Print When Expression" you should set something like: 

$V{NumRow} != 0 ? Boolean.TRUE : Boolean.FALSE

Hope this helps. 

Regards

Link to comment
Share on other sites

Thanks a lot...this is a great way to achieve this.

However, whenever I write the "Print When Expression" for a certain detail band, I am only able to to choose parameter from the main dataset and not from the subdataset...is there a way to "link" detail band and subdataset.

 

Thanks again for your help

Link to comment
Share on other sites

Hi Robert, 

I don't understand what you mean exactly with subdatasets... are you using subreports? In your first post you say that each detail contains 1 table of a dataset. Aren't you able to create a variable for each dataset and then use the same condition (with the corresponding variable in each detail band) to hide/show the band? May be attaching your jrxml will be easier to understand your problem and help you. 

Regards

Link to comment
Share on other sites

Thanks Augarte , this is my jrxml file.

 

What I have done in the report:

 

1 - I have created the main report (sql query SELECT 1 from DUAL)

 

2 - create 12 different datasets

 

3 - create 12 detail band, in each band 1 table (each table datasource corresponds to 1 dataset)

 

Whenever a table is empty, I want the band to be hidden. Otherwise I get empty lines in the report.

 

Thank you.

 

 

+++++++++++ JRXML FILE +++++++++ For some reason I am not able to post an answer ++++++++++++++

 

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

select SUM(iaas.init_qu - iaas.cancel_qu), service.finalclass as Service, operation.name as Operation, MONTHNAME(ch.date) as Month, 'Signed' as 'Signed'</p><p> from itop_serviceiaas iaas inner join itop_service service on iaas.id=service.id inner join itop_operationfamily operation on service.operationfamily_id=operation.id inner join itop_priv_changeop changeop on changeop.objkey=service.id inner join itop_priv_change ch on changeop.changeid=ch.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass group by Month,Operation;

select SUM(iaas.init_qu - iaas.cancel_qu), service.finalclass as Service, operation.name as Operation, MONTHNAME(ch.date) as Month, 'Installed' as 'Installed'</p><p> from itop_serviceiaas iaas inner join itop_service service on iaas.id=service.id inner join itop_operationfamily operation on service.operationfamily_id=operation.id inner join itop_priv_changeop changeop on changeop.objkey=service.id inner join itop_priv_change ch on changeop.changeid=ch.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass AND (service.status='Completed' OR service.status='Delivered') group by Month,Operation;

]]></fieldDescription></p><p> </field></p><p> </subDataset></p><p> <subDataset name="vmstotals" uuid="d229988a-8515-4ddb-b3a5-6914978fde71"></p><p> <queryString></p><p> <![CDATA[select service.finalclass as Service, SUM(iaas.init_qu-iaas.cancel_qu) as 'Active VMs', operation.name as Operation, 'Total' as 'Total', 'Signed' as 'Signed' from itop_service service</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id</p><p> inner join itop_serviceiaas iaas on iaas.id=service.id WHERE service.status!='Terminated' group by operation.name;

select service.finalclass as Service, SUM(iaas.init_qu-iaas.cancel_qu) as 'Active VMs', operation.name as Operation, 'Total' as 'Total', 'Installed' as 'Installed'</p><p> from itop_service service</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id</p><p> inner join itop_serviceiaas iaas on iaas.id=service.id WHERE (service.status='Completed' OR service.status='Delivered') group by operation.name;

]]></fieldDescription></p><p> </field></p><p> </subDataset></p><p> <subDataset name="spacetotal" uuid="6e2882d9-8654-4fbf-b305-84bb385527cc"></p><p> <queryString></p><p> <![CDATA[select service.finalclass as Service, SUM(space) as 'Space', operation.name as Operation, 'Total' as 'Total', 'Signed' as 'Signed'</p><p> from itop_service service</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id</p><p> inner join itop_servicecolocspace space on space.id=service.id WHERE service.status!='Terminated' AND (space.nracks=0 OR space.nracks IS NULL OR space.nracks='')</p><p> group by operation.name;

]]></fieldDescription></p><p> </field></p><p> <field name="Operation" class="java.lang.String"/></p><p> <field name="Total" class="java.lang.String"/></p><p> <field name="Signed" class="java.lang.String"/></p><p> </subDataset></p><p> <subDataset name="spacetotalinstalled" uuid="5ef73cea-3df2-4abe-807d-b422de6a7324"></p><p> <queryString></p><p> <![CDATA[select service.finalclass as Service, SUM(space) as 'Space', operation.name as Operation, 'Total' as 'Total', 'Installed' as 'Installed'</p><p> from itop_service service</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id</p><p> inner join itop_servicecolocspace space on space.id=service.id WHERE (service.status='Completed' OR service.status='Delivered') AND (space.nracks=0 OR space.nracks IS NULL OR space.nracks='')</p><p> group by operation.name;

]]></fieldDescription></p><p> </field></p><p> <field name="Operation" class="java.lang.String"/></p><p> <field name="Total" class="java.lang.String"/></p><p> <field name="Installed" class="java.lang.String"></p><p> <fieldDescription><![CDATA[

select SUM(space), service.finalclass as Service, operation.name as Operation, MONTHNAME(ch.date) as Month, 'Signed' as 'Signed' from itop_servicecolocspace space inner join itop_service service on space.id=service.id inner join itop_operationfamily operation on service.operationfamily_id=operation.id inner join itop_priv_changeop changeop on changeop.objkey=service.id inner join itop_priv_change ch on changeop.changeid=ch.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass AND (space.nracks=0 OR space.nracks IS NULL OR space.nracks='') group by Month,Operation;

select SUM(space), service.finalclass as Service, operation.name as Operation, MONTHNAME(ch.date) as Month, 'Installed' as 'Installed' from itop_servicecolocspace space inner join itop_service service on space.id=service.id inner join itop_operationfamily operation on service.operationfamily_id=operation.id inner join itop_priv_changeop changeop on changeop.objkey=service.id inner join itop_priv_change ch on changeop.changeid=ch.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass AND (space.nracks=0 OR space.nracks IS NULL OR space.nracks='') AND (service.status='Completed' OR service.status='Delivered') group by Month,Operation;

]]></fieldDescription></p><p> </field></p><p> </subDataset></p><p> <subDataset name="rackstotal" uuid="84d6fc21-64c3-4c33-88a5-ebe1ec34ac8f"></p><p> <queryString></p><p> <![CDATA[select SUM(numracks), Service,Operation,'Total' as 'Total','Signed' as 'Signed' from</p><p> (select service.finalclass as Service, SUM(case rack.init_qu WHEN '1' then 1 WHEN '0.5' then 0.5 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END)-SUM(case rack.cancel_qu WHEN '1' then 1 WHEN '0.5' then 0.5 WHEN '0.75' then 0.75 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END) AS numracks , operation.name as Operation from itop_service service join itop_operationfamily operation on service.operationfamily_id=operation.id inner join itop_servicecolocrack rack on rack.id=service.id WHERE service.status!='Terminated' group by Operation</p><p>&nbsp;</p><p> UNION</p><p>&nbsp;</p><p> select service.finalclass as Service, SUM(space.nracks) AS numracks, operation.name as Operation from itop_service service</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id</p><p> inner join itop_servicecolocspace space on space.id=service.id WHERE service.status!='Terminated' group by Operation</p><p> )c group by Operation

select SUM(numracks), Service,Operation,'Total' as 'Total','Installed' as 'Installed' from</p><p> (select service.finalclass as Service, SUM(case rack.init_qu WHEN '1' then 1 WHEN '0.5' then 0.5 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END)-SUM(case rack.cancel_qu WHEN '1' then 1 WHEN '0.5' then 0.5 WHEN '0.75' then 0.75 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END) AS numracks , operation.name as Operation from itop_service service join itop_operationfamily operation on service.operationfamily_id=operation.id inner join itop_servicecolocrack rack on rack.id=service.id WHERE (service.status='Completed' OR service.status='Delivered') group by Operation</p><p>&nbsp;</p><p> UNION</p><p>&nbsp;</p><p> select service.finalclass as Service, SUM(space.nracks) AS numracks, operation.name as Operation from itop_service service</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id</p><p> inner join itop_servicecolocspace space on space.id=service.id WHERE (service.status='Completed' OR service.status='Delivered') group by Operation</p><p> )c group by Operation

]]></fieldDescription></p><p> </field></p><p> </subDataset></p><p> <subDataset name="rackstotalpermonth" uuid="b814df13-d94a-4f54-8fe4-2222b8a0ab89"></p><p> <queryString></p><p> <![CDATA[select SUM(Racks),Service,Operation,Month,'Signed' as 'Signed' from</p><p> (</p><p> select SUM(case rack.init_qu WHEN '1' then 1 WHEN '0.75' then 0.75 WHEN '0.5' then 0.5 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END)- SUM(case rack.cancel_qu WHEN '1' then 1 WHEN '0.5' then 0.5 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END)</p><p> AS Racks ,</p><p> MONTHNAME(c.date) as Month,</p><p> service.finalclass as Service,</p><p> operation.name as Operation</p><p> from itop_priv_changeop changeop</p><p> inner join itop_priv_change c on changeop.changeid=c.id</p><p> inner join itop_servicecolocrack rack on rack.id=changeop.objkey</p><p> inner join itop_service service on rack.id=service.id</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass</p><p> group by MONTHNAME(c.date), operation.name</p><p>&nbsp;</p><p> UNION</p><p>&nbsp;</p><p> select SUM(space.nracks)</p><p> AS Racks ,</p><p> MONTHNAME(c.date) as Month,</p><p> service.finalclass as Service,</p><p> operation.name as Operation</p><p> from itop_priv_changeop changeop</p><p> inner join itop_priv_change c on changeop.changeid=c.id</p><p> inner join itop_servicecolocspace space on space.id=changeop.objkey</p><p> inner join itop_service service on space.id=service.id inner join itop_operationfamily operation on service.operationfamily_id=operation.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass</p><p> group by MONTHNAME(c.date), operation.name</p><p> )a group by Month, Operation

select SUM(Racks),'Colocation_Rack' as Service,Operation,Month, 'Installed' as 'Installed' from</p><p> (</p><p> select SUM(case rack.init_qu WHEN '1' then 1 WHEN '0.75' then 0.75 WHEN '0.5' then 0.5 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END)- SUM(case rack.cancel_qu WHEN '1' then 1 WHEN '0.5' then 0.5 WHEN '0.25' THEN 0.25 WHEN '0' then 0 END)</p><p> AS Racks ,</p><p> MONTHNAME(c.date) as Month,</p><p> service.finalclass as Service,</p><p> operation.name as Operation</p><p> from itop_priv_changeop changeop</p><p> inner join itop_priv_change c on changeop.changeid=c.id</p><p> inner join itop_servicecolocrack rack on rack.id=changeop.objkey</p><p> inner join itop_service service on rack.id=service.id</p><p> inner join itop_operationfamily operation on service.operationfamily_id=operation.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass AND (service.status='Completed' or service.status='Delivered')</p><p> group by MONTHNAME(c.date), operation.name</p><p>&nbsp;</p><p> UNION</p><p>&nbsp;</p><p> select SUM(space.nracks)</p><p> AS Racks ,</p><p> MONTHNAME(c.date) as Month,</p><p> service.finalclass as Service,</p><p> operation.name as Operation</p><p> from itop_priv_changeop changeop</p><p> inner join itop_priv_change c on changeop.changeid=c.id</p><p> inner join itop_servicecolocspace space on space.id=changeop.objkey</p><p> inner join itop_service service on space.id=service.id inner join itop_operationfamily operation on service.operationfamily_id=operation.id WHERE changeop.optype = 'CMDBChangeOpCreate' AND changeop.objclass=service.finalclass AND (service.status='Completed' or service.status='Delivered')</p><p> group by MONTHNAME(c.date), operation.name</p><p> )a group by Month, Operation

]]></fieldDescription></p><p> </field></p><p> </subDataset></p><p> <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"></p><p> <defaultValueExpression><![CDATA["/Users/robertabed/Desktop/Jasper/"

sELECT 1 from DUAL

Management Report

signed/Installed

Month/Total

Number

service

Operation

$F{Operation}

$F{Service}

$F{Active VMs}

$F{Total}

$F{Signed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(iaas.init_qu - iaas.cancel_qu)}

$F{Month}

$F{Installed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(iaas.init_qu - iaas.cancel_qu)}

$F{Month}

$F{Signed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{Active VMs}

$F{Total}

$F{Installed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{Space}

$F{Total}

$F{Signed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{Space}

$F{Total}

$F{Installed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(space)}

$F{Month}

$F{Signed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(space)}

$F{Month}

$F{Installed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(numracks)}

$F{Total}

$F{Signed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(numracks)}

$F{Total}

$F{Installed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(Racks)}

$F{Month}

$F{Signed}

$P{REPORT_CONNECTION}

$F{Operation}

$F{Service}

$F{SUM(Racks)}

$F{Month}

$F{Installed}

 

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