Jump to content
We've recently updated our Privacy Statement, available here ×
  • Multiple datasets, Exactly the same json (only one webservice call) - Extension and Another Example


    emistry
    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 :

    pic1(1).jpg.34c156e10c6438d820f1c7a0138f2de8.jpg


     

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

    pic3.jpg.3cd0b021b5cabd8e8325e1703045e4ba.jpg

    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.

    pic2.jpg.b10113c80a1af336169ce7a6726f2449.jpg

     
    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 :
     
    Untitled(10).jpg.c16a1a73f11553181df94e82b702bf63.jpg
     

    financialdata.jrxml


    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



    Guest
    This is now closed for further comments

×
×
  • Create New...