Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Using Javascript to change Aggregation Builder Expression
djatnieks
Can anyone tell me how to change the aggregation expression from the Aggregation Builder using Javascript?
I have a table with a group defined in the footer and a column that was defined using Aggregation Builder to have a function applied to an expression. E.g.
Aggregation Builder
Display Name: series1Agg
DataType: Integer
Function: COUNTDISTINCT
Expression: row["series1"]*2
Aggregate On: Group myGroup
What I am trying to do is to dynamically change the EXPRESSION using Javascript - anyone know how I can do that?
The XML of the report design for the expression looks like this:
<list-property name="arguments">
<structure>
<property name="name">Expression</property>
<expression name="value">row["series1"] * 2</expression>
</structure>
</list-property>
How can I access the contents of this stucture using Javascript??
Ok, so I have been able to use Javascript to change the aggregation function (by looking at the XML and guessing mostly), using this:
this.getDataBindings()[2].getStructure().setProperty("aggregateFunction", "Sum");
The XML for this was simpler:
<property name="aggregateFunction">COUNTDISTINCT</property>
Thanks in advance for any help,
dan
Find more posts tagged with
Comments
mwilliams
Hi Dan,
I have tried several things and have not been able to find out how as of yet. If I figure something out, I will post it in here.
djatnieks
Thanks for looking into this Michael. Here's what I finally ended up with - there must be a better way, especially a better way to access the data binding for the column.
I put this code in the onPrepare() for my table. I couldn't find a way to access the data binding from the column cell level.
importPackage(Packages.org.eclipse.birt.report.model.api.elements.structures);
// Create a new aggregation argument called Expression. There is one already
// existing in the rptdesign - adding a new one seems to either replace or
// be processed instead of the original.
var arg = new AggregationArgument();
arg.setName("Expression");
//Create the new expression value
var exprValue = "row["series1"] / 100" ; // this is actually dynamic based on parms not shown here
arg.setValue(exprValue);
// The already existing expression argument should probably be removed,
// but I don't know how to access it. The remove() method seems to
// require already knowing the argument being removed, but I could not
// find a way to get that.
//this.getDataBindings()[2].getStructure().removeArgument(existingarg);
// Add the new agg argument to the correct table column structure.
// If there is a better way to do this, I would be glad to learn about it!
this.getDataBindings()[2].getStructure().addArgument(arg);
// Now there are 2 arguments, but Birt seems to only use the newly
// added one, so it works.