Jump to content
Changes to the Jaspersoft community edition download ×
  • Multiple datasets, Exactly the same json (only one webservice call) - Extension and Another Example

    You can pass the datasource from master to subreport (or dataset) specifying a Datasource expression. 
    In this example we'll use the clone method on the datasource: ((com.jaspersoft.webservice.data.query.IWSDataSource)$P{REPORT_DATA_SOURCE}).clone(jsonRootNode,subFieldsMap) passing both parameters.
    Two parameters .clone(jsonRootNode,subFieldsMap) : you can specify both a new root path for the json AND a new mapping for the json fields.
    In the attached example FinancialData.jrxml, I have created JS Report with a Table using a Sub-Dataset. The parent JSON Query passes the clone method in the JRSDatasource Expression as shown here :



    ((com.jaspersoft.webservice.data.query.IWSDataSource)$P{REPORT_DATA_SOURCE}).clone("results", $P{SubFieldsMap})
    and the SubFieldMap Parameter is defined as [["symbol" : "symbol", "tradingDay": "tradingDay", "close": "close"]
    This is how I defined the parameter ..


    And these are the JSON Parameters I want to bring through in my Table using the Sub-Dataset. I passed the Symbol, TradingDay and Close fields to the Table, and therefore iterate through all the recurrences in the Results set.


    Note : I set the root as results in the clone call, as described by Gianluca in the original post. 
    Finally, set the report language to groovy as below :


    User Feedback

    Recommended Comments

    Hy, and instead inject in a Table componant (jr:table),

    it's possible to inject datas in a subReport ?


    As exemple with Table and DataSetRun + DataSourceExpression (is working) :

                    <jr:table>                    <datasetRun subDataset="Dataset1">                        <dataSourceExpression><![CDATA[((com.jaspersoft.webservice.data.query.IWSDataSource)$P{REPORT_DATA_SOURCE}).clone("results", $P{SubFieldsMap})]]></dataSourceExpression>


    As wanted for call, a subreport for each node :

                <subreport>                <reportElement/>                <dataSourceExpression><![CDATA[((com.jaspersoft.webservice.data.query.IWSDataSource)$P{REPORT_DATA_SOURCE}).clone("@.results", $P{SubFieldsMap})]]></dataSourceExpression>                <subreportExpression><![CDATA["testsub_sub.jasper"]]></subreportExpression>            </subreport>

    With a JSON like :

    [{"id": 123,"result": [{   "symbol": "S_A_1"   },{   "symbol": "S_A_2"   }]},{"id": 456,"result": [{   "symbol": "S_B_1"   },{   "symbol": "S_B_2"   }]}]

    For first subreport call, it will use array S_A_1, and S_A_2
    For second subreport call, it will use array S_B_1, and S_B_2


    Link to comment
    Share on other sites

    This is now closed for further comments

  • Create New...