jasper report passing parameter from list index

3.2k views Asked by At

I got a scenario where I need to pass jasper report parameter value from a list using index.

I have the following query executed in the jasper report, with the following parameters defined.

    <parameter name="clientServiceIds" class="java.util.Collection"/>
        <parameter name="trafficPeriod" class="java.util.Collection"/>
        <parameter name="transactionType" class="java.util.Collection"/>
        <parameter name="transactionStatus" class="java.util.Collection"/>
        <parameter name="roamingPartners" class="java.util.Collection"/>
        <parameter name="ages" class="java.util.Collection"/>

        SELECT
          CLIENT_CODE,
          PARTNER_ORG,
            PARTNER_CODE,
          SERVICE_TYPE,
          TP_ID,
          TRAFFIC_PERIOD,
          SETTLEMENT_TYPE,
          SDR_NET,
          TRAN_CURR_NET,
          TRAN_CURRENCY_ID,
          DUE_DATE,
          TRANSACTION_TYPE,
          STATUS,
          NOTE_ID,
          AGE
        FROM vw_transaction_search
        WHERE $X{IN, client_service_id, clientServiceIds}
        AND $X{IN, PARTNER_SERVICE_ID, roamingPartners}
        AND $X{IN, traffic_period, trafficPeriod}
        AND $X{IN, transaction_type, transactionType}
        AND $X{IN, status_id, transactionStatus}
        AND AGE BETWEEN $P{param1} AND $P{param2}

Here ages is a list which I am passing to the report, which contains two values at index 0 and index 1. All parameters (paramValueMap) I am getting from an external system which i cannot modify,

JasperFillManager.fillReport(jasperReport, paramValueMap, connection);

so I am looking for a way to pass parameters param1 and param2 in my Jasper report SQL from my Collection ages, something like param1=ages.get(0) and param2=ages.get(1), so the SQL will be something like

...AND $X{IN, status_id, transactionStatus}
AGE BETWEEN $P{ages.get(0)} AND $P{ages.get(1)}

is there any way possible to achieve this?

1

There are 1 answers

1
S.Jose On BEST ANSWER

I was able to crack this down by adding two additional parameters age1 & age2 and passing the value to the added parameters from the list here are the details.

<parameter name="trafficPeriod" class="java.util.Collection"/>
    <parameter name="transactionType" class="java.util.Collection"/>
    <parameter name="transactionStatus" class="java.util.Collection"/>
    <parameter name="roamingPartners" class="java.util.Collection"/>
    <parameter name="age" class="java.util.List" isForPrompting="false"/>
    <parameter name="age1" class="java.lang.Integer" isForPrompting="false">
        <defaultValueExpression><![CDATA[$P{age}.get(0)]]></defaultValueExpression>
    </parameter>
    <parameter name="age2" class="java.lang.Integer" isForPrompting="false">
        <defaultValueExpression><![CDATA[$P{age}.get(1)]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT
  CLIENT_CODE,
  PARTNER_ORG,
    PARTNER_CODE,
  SERVICE_TYPE,
  TP_ID,
  TRAFFIC_PERIOD,
  SETTLEMENT_TYPE,
  SDR_NET,
  TRAN_CURR_NET,
  TRAN_CURRENCY_ID,
  DUE_DATE,
  TRANSACTION_TYPE,
  STATUS,
  NOTE_ID,
  AGE
FROM vw_transaction_search
WHERE $X{IN, client_service_id, clientServiceIds}
AND $X{IN, PARTNER_SERVICE_ID, roamingPartners}
AND $X{IN, traffic_period, trafficPeriod}
AND $X{IN, transaction_type, transactionType}
AND $X{IN, status_id, transactionStatus}
AND AGE BETWEEN $P{age1} AND $P{age2}
ORDER BY client_code,
  partner_code,
  traffic_period,
  age]]>
    </queryString>