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)
Aggregation in BeforeFactory
fussballnik15
Hello,<br><br>
does anyone know, how i can build a new Aggregation in the BeforeFactory-Method?<br><br>
Greetings,<br>
Nik
Find more posts tagged with
Comments
Clement Wong
<p>Attached is a sample the creates an aggregation (average MSRP) for a table in the beforeFactory.</p>
<pre class="_prettyXprint">
importPackage( Packages.org.eclipse.birt.report.model.api );
var design= reportContext.getReportRunnable().designHandle.getDesignHandle();
var elementFactory = design.getElementFactory();
var table = design.findElement("myTable");
var aggrCC = StructureFactory.createComputedColumn();
aggrCC.setName("AVE_MSRP");
aggrCC.setAggregateFunction("AVE");
//If you have a group
//aggrCC.addAggregateOn("Product Code Group");
aggrCC.setDataType("Decimal");
aggrCC.setExpression("row[\"MSRP\"]");
table.getColumnBindings().addItem(aggrCC);
</pre>
<p>You didn't mention which version of BIRT you are using so I tested it both on commercial iHub 3.1 and OS BIRT 4.5.0, and both produced the expected results.</p>
<p> </p>
fussballnik15
<p>This didnt work for me:</p>
<pre class="_prettyXprint _lang-js">
var aggrCC = StructureFactory.createComputedColumn();
aggrCC.setName("SUM_NO4");
aggrCC.setAggregateFunction("Sum");
//If you have a group
//aggrCC.addAggregateOn("Product Code Group");
aggrCC.setDataType("Decimal");
aggrCC.setExpression("row[\"No4\"]");
mytable.getColumnBindings().addItem(aggrCC);
var mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "SUM_NO4");
var myheader = mytable.getFooter( ).get( 0 );
var hcell = myheader.getCells( ).get( 4 );
hcell.getContent().add(mydata);
</pre>
<p>The Report crashes because of this: "mytable.getColumnBindings().addItem(aggrCC);"</p>
<p>But I didnt get any Errors. Im working with BIRT Version 2.3.2</p>
pricher
<p>Hi,</p>
<p> </p>
<p>In you code snippet, I don't see where you defined <em>mytable</em>. This object has to be initialized before you make a call on it.</p>
<p> </p>
<p>BTW, the code sent earlier by Clement works fine in 2.3.2</p>
<p> </p>
<p>P.</p>
fussballnik15
The table is initalized like in the example of Clement.
pricher
<p>Hi,</p>
<p> </p>
<p>Can you share your report design? </p>
<p> </p>
<p>P.</p>
fussballnik15
<p>Here it is, i dont know why this isn't working.</p>
<p> </p>
<p>Nik</p>
pricher
<p>Hi Nik,</p>
<p> </p>
<p>Because I don't have access to the datasource to run your example, it is very hard for me to debug.</p>
<p> </p>
<p>Sorry about that.</p>
<p> </p>
<p>P.</p>