Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Sub-reports with scripted data sets
Patrick1974
I have a report that's using daos to gather the data. I've tried using Java event handlers as well as the JavaScript. I do fine with both for simple reports, but I can't figure out how to grab the data for sub-reports (and sub-sub-reports, etc). There is no JDBC connectivity; we're only dealing with collections of Java objects.
I have a collection of customer objects, each of which has a collection of order objects.
What I have now in both Java and JS is that I call my dao object's getData method in the open or beforeOpen methods. That gives me my collection of customers. Iterating over them with my fetch works great, but I cannot get the orders.
In JS, I tried creating a global list of the iterators for order collections. After each customer fetch, I would add its orders to that list. I thought that would work, but debugging seems to show that the open, fetch, close don't necessarily operate in the expected order for the sub-report.
Any help or examples of doing the above would be much appreciated.
Thank you very much.
Find more posts tagged with
Comments
dee_jgd
Hi there
I am having the same problem. I have Java objects with lists that need to be displayed by using subreports but can't get the scripting right.
Have you resolved this? If so, please post the solution.
Thanks
dee_jgd
Hope this will save others some time as I battled with this for a few days.
I didn't have any luck with Javascript, but managed to find a solution using Java event handlers. In java you would code the DAO's such that each object can then get the list of subDao's e.g in the ParentDAO you would have a getChildren() method. However, I could not find a way to map this Children list in BIRT. A way to get around it is to get the children by parent i.e. public List<Child> getChidlren(String parentId).
Steps to do it
1. In report designer, Create a ParentDataSet with fields e.g parentId, parentName
2. In report designer, Create a ChildDataSet with fields e.g. childId, childName
3. In report designer, Create a Parameter which will bind the two sets e.g. parent_id_param
4. In report designer, On ParentDataSet, add an eventhandler class e.g. ParentDSEventHandler. In Java/eclipse IDE create the class that extends ScriptedDataSetEventAdapter implements IScriptedDataSetEventHandler.
This will override the open, fetch etc
5. In report designer,On ChildDataSet, add an eventhandler class e.g. ChildDSEventHandler. In Java/eclipse IDE create the class like above.This will override the open, fetch etc, BUT in the beforeOpen method, get the parameter value for the parent. THen in the open method get the children for the parent e.g.
@Override
public void beforeOpen(IDataSetInstance dataSet, IReportContext reportContext) {
super.beforeOpen(dataSet, reportContext);
if (reportContext.getParameterValue("parent_id_param") != null)
PARENT_ID = (String) reportContext.getParameterValue("parent_id_param");
}
@Override
public void open(IDataSetInstance dataSet) {
ReportSource rs = new ReportSource();
childrenList = rs.getChildrenList(PARENT_ID);
totalRows = childrenList.size();
currentRow = 0;
}
This assumes you creates ReportSource class which has methods:
- getParentList()
- getChildrenList(String parentId)
6. In reportdesign, add a list and bind it to parentDataSet. Where you display the parentName, add to expressionbuilder:
params["parent_id_param"] = dataSetRow["parentId"]
dataSetRow["parentId"]
This binds the parameter to the current parent in the list.
Test and smile
)
P.S You can repeat this for as many sub lists as you have.
SatishD
Hi,
I am having same problem . Could you please elaborate step 3 of creating a parameter which bind the two sets.
Thanks,
Satish
Pandiyan
Hi,<br />
<br />
Your article is very good.<br />
<br />
I have done the same way other than the Open() logic instead of setting to ReportSource. I have settled to global object the ResultSet return from DAO class.<br />
<br />
In the Fetch() method, getting the global object value and try to read and set the row data.<br />
But I am not able to see the result in report. The parent row data displayed but the child data are not display.<br />
<br />
Note: the child DAO query is executed with data. I have created the bind variable for child DS and I am able to get values in hander class.<br />
<br />
Please can you help me, how to work the parent child report in BIRT with scripted data set in BIRT because i tryied may ways but i could not able to completed.<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'dee_jgd'" data-cid="46828" data-time="1240495639" data-date="23 April 2009 - 07:07 AM"><p>
Hope this will save others some time as I battled with this for a few days.<br />
<br />
<br />
I didn't have any luck with Javascript, but managed to find a solution using Java event handlers. In java you would code the DAO's such that each object can then get the list of subDao's e.g in the ParentDAO you would have a getChildren() method. However, I could not find a way to map this Children list in BIRT. A way to get around it is to get the children by parent i.e. public List<Child> getChidlren(String parentId).<br />
<br />
<br />
Steps to do it
<br />
<br />
<br />
1. In report designer, Create a ParentDataSet with fields e.g parentId, parentName<br />
<br />
2. In report designer, Create a ChildDataSet with fields e.g. childId, childName<br />
<br />
3. In report designer, Create a Parameter which will bind the two sets e.g. parent_id_param<br />
<br />
4. In report designer, On ParentDataSet, add an eventhandler class e.g. ParentDSEventHandler. In Java/eclipse IDE create the class that extends ScriptedDataSetEventAdapter implements IScriptedDataSetEventHandler.<br />
<br />
This will override the open, fetch etc<br />
<br />
5. In report designer,On ChildDataSet, add an eventhandler class e.g. ChildDSEventHandler. In Java/eclipse IDE create the class like above.This will override the open, fetch etc, BUT in the beforeOpen method, get the parameter value for the parent. THen in the open method get the children for the parent e.g.<br />
<br />
<br />
@Override<
;br />
<br />
public void beforeOpen(IDataSetInstance dataSet, IReportContext reportContext) {<br />
<br />
super.beforeOpen(dataSet, reportContext);<br />
<br />
if (reportContext.getParameterValue("parent_id_param") != null)<br />
<br />
PARENT_ID = (String) reportContext.getParameterValue("parent_id_param");<br />
<br />
}<br />
<br />
<br />
<br />
@Override<
;br />
<br />
public void open(IDataSetInstance dataSet) {<br />
<br />
ReportSource rs = new ReportSource();<br />
<br />
childrenList = rs.getChildrenList(PARENT_ID);<br />
<br />
totalRows = childrenList.size();<br />
<br />
currentRow = 0;<br />
<br />
}<br />
<br />
<br />
This assumes you creates ReportSource class which has methods:<br />
<br />
- getParentList()<br />
<br />
- getChildrenList(String parentId)<br />
<br />
<br />
6. In reportdesign, add a list and bind it to parentDataSet. Where you display the parentName, add to expressionbuilder:<br />
<br />
params["parent_id_param"] = dataSetRow["parentId"]<br />
<br />
dataSetRow["parentId"]<br />
<br />
<br />
This binds the parameter to the current parent in the list.<br />
<br />
<br />
Test and smile
)<br />
<br />
<br />
P.S You can repeat this for as many sub lists as you have.<br /></p></blockquote>