0
votes

I'm a total beginner with Birt (actually it's my first day with it) and my task is to create a Birt report that looks exactly like one done in Flash/Flex ... This report is looking really well.

The problem is: Im my Flex solution I have one field of a DataGrid that consists of a Label followed by a numeric output, if the numeric value is 0 or greater.

Based upon two values of a recordsets row I get an Internationalized Value by applying Mapping features of Birt (This allready works great). The resulting String should then be appended with "({value})" if value is greater or equal 0.

When using the designer, I can only place a second field in it's own table cell or table row, but I seem to be unable to output both fields in one table cell.

It would be great if someone could guide me through this.

Chris

2

2 Answers

2
votes

You may build entire string in Dynamic Text JavaScript expession.

Using i18n in Javascript is briefly described in BIRT FAQ. The one interesting question could be How can I localize strings in JavaScript - this expression gives localized text:

reportContext.getMessage("companyNameKey", reportContext.getLocale())

Row data is stored in the row array. All available fields you can find in an Expression Builder. As you found and double-clicked desired field, it appears expression like this:

row["FOO_NUMBER"].value

Putting all together:

reportContext.getMessage("Foo number:", reportContext.getLocale()) + 
  (row["FOO_NUMBER"].value > 0) ? ( "("+row["FOO_NUMBER"].value+")" ) : ("")
1
votes

Thanks to jinowolskis post ... just wanted to add the full solution just if anyone runs into the same problem :-)

importPackage( Packages.java.text );
var myKey = "" + row["vulnerabilityClass"] + "." + row["result"];
if(row["cvssScore"] >= 0) {
    var nf = NumberFormat.getNumberInstance(reportContext.getLocale());
    nf.setMinimumFractionDigits(1);
    nf.setMaximumFractionDigits(1);
    reportContext.getMessage(myKey, reportContext.getLocale()) + " (" + nf.format(row["cvssScore"]) + ")";
} else {
    reportContext.getMessage(myKey, reportContext.getLocale());
}