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 :
Recommended Comments