Hello,
I need to assistance in writting the java script within the BIRT design file to sum the dynamic columns that I am adding to the report design file.
I have the logic from other topics to add the column header, group header, detail values into the report. But I can't figure out the class (which I believe is the Total) and how to set the objects in my scripts.
Below is the the script (onPrepare) that I am currently using to generate the columns. It works except for aggregation of the columns at the group level.
I am using:
Windows 7 64bit
Eclipse IDE Version: Indigo Service Release 2 Build id: 20120216-1857
birt: 3.7.2
Thanks in Advance for your help!
Mike W
======================= javascript below ==========================================
importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
importPackage( Packages.org.eclipse.birt.report.model.api);
importPackage( Packages.org.eclipse.birt.report.engine.api.aggregation.*);
var myColValue =new Array();
myColValue[0] = "P_VALUE_1";
myColValue[1] = "P_VALUE_2"
myColValue[2] = "P_VALUE_3"
myColValue[3] = "P_VALUE_4"
myColValue[4] = "P_VALUE_5"
myColValue[5] = "P_VALUE_6"
var myColHeader = new Array();
myColHeader[0] = "CY2010";
myColHeader[1] = "CY2011"
myColHeader[2] = "CY2012"
myColHeader[3] = "CY2013"
myColHeader[4] = "CY2014"
myColHeader[5] = "Total"
log (" myColValue.length |" + myColValue.length + "|");
if ( myColValue.length >= 0 ){
var i = 0;
var str = "";
sef = SimpleElementFactory.getInstance();
elementFactory = reportContext.getDesignHandle().getElementFactory();
var mytable = reportContext.getDesignHandle().findElement("Cost By Date");
for(i=0;i<myColValue.length;i++)
{
var icnt = i;
var iColOffset = 2;
// Add column
log(" TABLE - onPrepare -- adding column to report");
var incnt = i;
mytable.insertColumn(incnt+2,1);
// Add Group column headers
log(" TABLE - onPrepare - added column header");
var myheader = mytable.getGroups().get( 0 ).getHeader().get( 1 ) // Group1 Header row 2
var tcell = myheader.getCells( ).get( incnt+iColOffset);
var mylabel = elementFactory.newLabel( null );
mylabel.setText( myColHeader[i]);
tcell.getContent( ).add( mylabel );
// Add Detail Rows
log(" TABLE - onPrepare - added data items"); // Detail Row
var mydetail = mytable.getDetail( ).get( 0 );
var tcell = mydetail.getCells( ).get( incnt+iColOffset);
mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "P_VALUE_" + (i + 1) );
tcell.getContent( ).add( mydata );
// Add Group Footer rows (sum totals)
var myfooter = mytable.getGroups().get( 0 ).getFooter().get( 0 ) // Group1 Footer ????
var tfcell = myfooter.getCells( ).get( incnt+iColOffset);
var myflabel = elementFactory.newLabel( null );
myflabel.setText( myColHeader[i]);
tfcell.getContent( ).add( myflabel );
}
}
I need to assistance in writting the java script within the BIRT design file to sum the dynamic columns that I am adding to the report design file.
I have the logic from other topics to add the column header, group header, detail values into the report. But I can't figure out the class (which I believe is the Total) and how to set the objects in my scripts.
Below is the the script (onPrepare) that I am currently using to generate the columns. It works except for aggregation of the columns at the group level.
I am using:
Windows 7 64bit
Eclipse IDE Version: Indigo Service Release 2 Build id: 20120216-1857
birt: 3.7.2
Thanks in Advance for your help!

Mike W
======================= javascript below ==========================================
importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
importPackage( Packages.org.eclipse.birt.report.model.api);
importPackage( Packages.org.eclipse.birt.report.engine.api.aggregation.*);
var myColValue =new Array();
myColValue[0] = "P_VALUE_1";
myColValue[1] = "P_VALUE_2"
myColValue[2] = "P_VALUE_3"
myColValue[3] = "P_VALUE_4"
myColValue[4] = "P_VALUE_5"
myColValue[5] = "P_VALUE_6"
var myColHeader = new Array();
myColHeader[0] = "CY2010";
myColHeader[1] = "CY2011"
myColHeader[2] = "CY2012"
myColHeader[3] = "CY2013"
myColHeader[4] = "CY2014"
myColHeader[5] = "Total"
log (" myColValue.length |" + myColValue.length + "|");
if ( myColValue.length >= 0 ){
var i = 0;
var str = "";
sef = SimpleElementFactory.getInstance();
elementFactory = reportContext.getDesignHandle().getElementFactory();
var mytable = reportContext.getDesignHandle().findElement("Cost By Date");
for(i=0;i<myColValue.length;i++)
{
var icnt = i;
var iColOffset = 2;
// Add column
log(" TABLE - onPrepare -- adding column to report");
var incnt = i;
mytable.insertColumn(incnt+2,1);
// Add Group column headers
log(" TABLE - onPrepare - added column header");
var myheader = mytable.getGroups().get( 0 ).getHeader().get( 1 ) // Group1 Header row 2
var tcell = myheader.getCells( ).get( incnt+iColOffset);
var mylabel = elementFactory.newLabel( null );
mylabel.setText( myColHeader[i]);
tcell.getContent( ).add( mylabel );
// Add Detail Rows
log(" TABLE - onPrepare - added data items"); // Detail Row
var mydetail = mytable.getDetail( ).get( 0 );
var tcell = mydetail.getCells( ).get( incnt+iColOffset);
mydata = elementFactory.newDataItem( null );
mydata.setResultSetColumn( "P_VALUE_" + (i + 1) );
tcell.getContent( ).add( mydata );
// Add Group Footer rows (sum totals)
var myfooter = mytable.getGroups().get( 0 ).getFooter().get( 0 ) // Group1 Footer ????
var tfcell = myfooter.getCells( ).get( incnt+iColOffset);
var myflabel = elementFactory.newLabel( null );
myflabel.setText( myColHeader[i]);
tfcell.getContent( ).add( myflabel );
}
}