hal_1 Posted April 18, 2018 Share Posted April 18, 2018 I have setup a parameter as a java.util.collection, let's call it var1I use this in my where clause so if nothing is selected for the parameter, I will get a match. It looks like this:and ($X{IN,null,var1} or $X{IN, column_1, var1})I've been doing this for over 5 years and now it doesn't want to work when I don't select anything for the parameter. Any ideas why? Link to comment Share on other sites More sharing options...
mlopez_1 Posted April 18, 2018 Share Posted April 18, 2018 You can use var1.size() > 0 to know if some value was added, but if no values was added.For better understanding you must check out this URL: http://jasperreports.sourceforge.net/sample.reference/query/Mariano Link to comment Share on other sites More sharing options...
joseng62 Posted April 18, 2018 Share Posted April 18, 2018 What is the deafult value in the expression for the given parameter ? You need to instantiate an empty array in the expression : new ArrayList(Arrays.asList()) which will give you the all effect. Select all. You could create another parameter that does a check if array is empty (there should be is empty method) and then use that array in your sql query to either pass a empty array or the array as is with values selected already. Link to comment Share on other sites More sharing options...
hal_1 Posted April 22, 2018 Author Share Posted April 22, 2018 I created a small report to demonstrate how I understand the java.collection to work. The parametersterm_select and SelectForm_Status should both work finding any item the user selects and if they don't enter anything for the parameter, all records are returned. If I don't enter a valid option for the java.collection parameters, I don't find any records.Here's the code:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1 --><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="Blank_Letter_Landscape" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1d7a2027-5a37-43de-a7c1-713306fb74e0"><property name="com.jaspersoft.studio.data.sql.tables" value=""/><property name="com.jaspersoft.studio.data.defaultdataadapter" value="xxxxxxx"/><property name="ireport.jasperserver.url" value="http://xx.xx.xx.xx:8080/jasperserver/"/><property name="ireport.jasperserver.user" value="xxx"/><property name="ireport.jasperserver.reportUnit" value="/Time2Track/Administrators/Blank_Letter_Landscape"/><property name="ireport.jasperserver.report.resource" value="/Time2Track/Administrators/Blank_Letter_Landscape_files/main_jrxml"/><parameter name="school_id" class="java.lang.String"/><parameter name="Select_Form" class="java.lang.String"/><parameter name="Select_Form_Status" class="java.util.Collection" nestedType="java.lang.String" evaluationTime="Early"><defaultValueExpression><![CDATA[new ArrayList(Arrays.asList())]]></defaultValueExpression></parameter><parameter name="term_select" class="java.util.Collection" nestedType="java.lang.String" evaluationTime="Early"><defaultValueExpression><![CDATA[new ArrayList(Arrays.asList())]]></defaultValueExpression></parameter><parameter name="submission_start_date" class="java.util.Date"/><parameter name="submission_end_date" class="java.util.Date"/><queryString language="SQL"><![CDATA[-- value_counts subqueryselect --form_submission_items.`form_item_id` as form_item_id, -- case when $Xx{IN,null,term_select} then 1 else 0 end as term_null,"" as term_null,form_submission_items.value as value,case when form_submission_items.value like "%|%" then form_submission_items.value_label else form_item_values.label end as value_label,form_submission_items.value_label as label,count(distinct (case when form_submission_items.value in ("N/A","N/R","N/O") then null else form_submission_items.id end)) as value_count from form_submission_itemsleft join form_submission_sections on form_submission_items.`form_submission_section_id` = form_submission_sections.idleft join form_submissions on form_submission_sections.`form_submission_id` = form_submissions.idleft join practicums on practicums.id = form_submissions.practicum_idleft join form_item_values on form_submission_items.`form_item_id` = form_item_values.`form_item_id` and form_submission_items.value = form_item_values.valueleft join forms on form_submissions.form_id = forms.idwhere forms.school_id = $P{school_id} and forms.id = $P{Select_Form} and ($X{IN,null,Select_Form_Status} or $X{IN, form_submissions.status, Select_Form_Status}) >>>>> This is where I'm having a problemand ($X{IN,null,term_select} or $X{IN, practicums.term_id,term_select}) >>>>> This is where I'm having a problem I want to find all records if nothing is entered for term_select-- and (case when $Xx{IN,null,term_select} then 1 else 0 end = 0 or $Xx{IN, practicums.term_id, term_select})and ($P{submission_start_date} is null or date(form_submissions.requested_at) between $P{submission_start_date} and $P{submission_end_date})and form_submission_items.`input_type` in ("radio", "checkbox","select","text_area")group by form_item_id,valueorder by form_item_id,value]]></queryString><field name="form_item_id" class="java.lang.Integer"><property name="com.jaspersoft.studio.field.label" value="form_item_id"/><property name="com.jaspersoft.studio.field.tree.path" value="form_submission_items"/></field><field name="term_null" class="java.lang.String"/><field name="value" class="java.lang.String"><property name="com.jaspersoft.studio.field.label" value="value"/><property name="com.jaspersoft.studio.field.tree.path" value="form_submission_items"/></field><field name="value_label" class="java.lang.String"><property name="com.jaspersoft.studio.field.label" value="value_label"/></field><field name="label" class="java.lang.String"><property name="com.jaspersoft.studio.field.label" value="label"/><property name="com.jaspersoft.studio.field.tree.path" value="form_submission_items"/></field><field name="value_count" class="java.lang.Long"><property name="com.jaspersoft.studio.field.label" value="value_count"/></field><background><band splitType="Stretch"/></background><title><band splitType="Stretch"/></title><pageHeader><band height="11" splitType="Stretch"/></pageHeader><columnHeader><band height="20" splitType="Stretch"><staticText><reportElement x="0" y="0" width="152" height="15" uuid="b1cc853b-3667-444c-a331-3906097e574b"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="11ee2ebd-abb3-40b6-b273-5a217c08af82"/></reportElement><text><![CDATA[form_item_id]]></text></staticText><staticText><reportElement x="152" y="0" width="150" height="15" uuid="a8bab78a-1f92-440f-9a92-edd5bfeaf88a"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="def49dd4-2c7c-4c2a-8345-9250be174ffc"/></reportElement><text><![CDATA[value]]></text></staticText><staticText><reportElement x="302" y="0" width="150" height="15" uuid="8d7e6058-5abc-49a3-8443-267ca11da29e"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="dc96bfc9-4581-496b-ba04-87f7650f71d1"/></reportElement><text><![CDATA[value_label]]></text></staticText><staticText><reportElement x="452" y="0" width="150" height="15" uuid="20eb8f99-e07d-450c-ad81-a690d13bc9d6"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7ea9a36c-8ad2-4b3d-a768-a5a766220bc2"/></reportElement><text><![CDATA[label]]></text></staticText><staticText><reportElement x="602" y="0" width="150" height="15" uuid="f847718d-7450-42f6-9a35-e8fdc36dbbfa"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="af80e1f4-8c05-47e9-bb32-3ea29bfd3e86"/></reportElement><text><![CDATA[value_count]]></text></staticText></band></columnHeader><detail><band height="20" splitType="Stretch"><textField><reportElement x="0" y="0" width="152" height="15" uuid="0ce4bcdb-83cf-44f3-a3be-796974c7699b"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="11ee2ebd-abb3-40b6-b273-5a217c08af82"/></reportElement><textFieldExpression><![CDATA[$F{form_item_id}]]></textFieldExpression></textField><textField><reportElement x="152" y="0" width="150" height="15" uuid="0f4f5d5f-a7e3-437a-bc33-063b58a5fafe"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="def49dd4-2c7c-4c2a-8345-9250be174ffc"/></reportElement><textFieldExpression><![CDATA[$F{value}]]></textFieldExpression></textField><textField><reportElement x="302" y="0" width="150" height="15" uuid="af03504d-00f2-47b2-af1a-80d00c9517bb"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="dc96bfc9-4581-496b-ba04-87f7650f71d1"/></reportElement><textFieldExpression><![CDATA[$F{value_label}]]></textFieldExpression></textField><textField><reportElement x="452" y="0" width="150" height="15" uuid="4b788aa1-cc8f-4d76-8ff3-85cf76ce756f"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7ea9a36c-8ad2-4b3d-a768-a5a766220bc2"/></reportElement><textFieldExpression><![CDATA[$F{label}]]></textFieldExpression></textField><textField><reportElement x="602" y="0" width="150" height="15" uuid="6e60f3d6-f953-4f9c-a5f6-0ef60f71d168"><property name="com.jaspersoft.studio.spreadsheet.connectionID" value="af80e1f4-8c05-47e9-bb32-3ea29bfd3e86"/></reportElement><textFieldExpression><![CDATA[$F{value_count}]]></textFieldExpression></textField></band></detail><columnFooter><band height="21" splitType="Stretch"/></columnFooter><pageFooter><band height="54" splitType="Stretch"/></pageFooter><summary><band height="42" splitType="Stretch"/></summary></jasperReport> Thanks, Hal Link to comment Share on other sites More sharing options...
sfitzsim Posted September 22, 2020 Share Posted September 22, 2020 Per community user, Cliff CowperthwaitI got it to work by using a subquery(highlighted): It appears to be the only way to use the Collection Type in a $X{IN } Select * from (select distinct fgbencd_orgn_code "ORGN", O.ftvorgn_title "DEPARTMENT", fgbencd_fund_code "FUND", ftvfund_ftyp_code "TYPE", fgbencd_acct_code "ACCT", fgbench_num "PO", spriden_id "VENDORID", spriden_last_name "NAME", fgbench_estab_date "ESTABLISHED", sum(nvl(fgbencp_orig_encb_amt,0)) "ORIGINALENC", sum(nvl(fgbencp_orig_encb_amt,0)+ nvl(fgbencp_sum_encb_adjt,0)+ nvl(fgbencp_sum_encb_liq,0)) "ROLLOVERAMT"FROM fimsmgr.fgbench inner join fimsmgr.fgbencd on fgbencd_num = fgbench_num inner join fimsmgr.fgbencp on fgbencp_num = fgbencd_num and fgbencp_item = fgbencd_item and fgbencp_seq_num = fgbencd_seq_num inner join saturn.spriden on spriden_pidm = fgbench_vendor_pidm and spriden_change_ind is null inner join fimsmgr.ftvfund on ftvfund_fund_code = fgbencd_fund_code and ftvfund_eff_date = (select max(ftvfund_eff_date) from FTVFUND I where ftvfund_fund_code = fgbencd_fund_code) inner join fimsmgr.ftvorgn O on O.ftvorgn_orgn_code = fgbencd_orgn_code and O.ftvorgn_eff_date = (select max(ftvorgn_eff_date) from ftvorgn where ftvorgn_orgn_code = O.ftvorgn_orgn_code )WHERE Substr(ltrim(fgbench_num),1,1) NOT IN ('R','E')and FGBENCH_STATUS_IND <> 'C'and FGBENCD_STATUS <> 'C'AND fgbench_estab_date >= '01-oct-2000'AND fgbench_estab_date <= '03-mar-2099'AND fgbencp_fsyr_code = (SELECT substr(to_char(MAX(to_number(fofycnv(fgbencp_fsyr_code)))),3,2) FROM fgbencp WHERE fgbencp_num = fgbencd_num AND fgbencp_item = fgbencd_item AND fgbencp_seq_num = fgbencd_seq_num )and 0 < (SELECT sum(nvl(fgbencp_orig_encb_amt,0)+ nvl(fgbencp_sum_encb_adjt,0)+ nvl(fgbencp_sum_encb_liq,0)) FROM fgbencp WHERE fgbencp_num = fgbench_num AND fgbencp_item = fgbencd_item AND fgbencp_seq_num = fgbencd_seq_num AND fgbencp_fsyr_code = (SELECT substr(to_char(MAX(to_number(fofycnv(fgbencp_fsyr_code)))),3,2) FROM fgbencp WHERE fgbencp_num = fgbencd_num AND fgbencp_item = fgbencd_item AND fgbencp_seq_num = fgbencd_seq_num ))and1= CASE When $P{VENNUM} is null then 1 When spriden_id like concat(concat('%' , $P{VENNUM}) , '%' ) then 1 else 0 ENDGROUP BY fgbencd_orgn_code , ftvorgn_title, fgbencd_fund_code , ftvfund_ftyp_code , fgbencd_acct_code , fgbench_num, spriden_id , spriden_last_name , fgbench_estab_date) where $X{IN, ORGN, DEPT} and $X{IN, ACCT, ACCTS} and $X{IN, FUND, FUNDS} Hit “READ FIELDS” and save it. The create a query List Of Values on the server to match. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now