Combining a JavaScript expression and static text
BIRT Report Designer provides a useful tag, VALUE-OF, which you use to insert a dynamic value in a text element. Using the VALUE-OF tag, you can insert any JavaScript expression.
The following example shows static text combined with a value that a JavaScript function returns.
Text that you supply:
Report generated on <VALUE-OF>new Date()</VALUE-OF>
Output:
Report generated on Jan 19, 2010 12:30 PM
The following example shows static text combined with a conditional expression and a field value expression.
Text that you supply:
Dear <VALUE-OF>row["Sex"] == "M" ? "Mr." : "Ms."</VALUE-OF><VALUE-OF>row["Name"]</VALUE-OF>,
Output:
Dear Mr. Scott Johnson,
Dear Ms. Ella Parker,
As the example shows, a conditional expression can have one of two values based on a condition. The syntax for this conditional expression is
condition ? value1 : value2
If the condition is true, the expression has the value of value1; otherwise, it has the value of value2.
Alternatively, you can use an if...else statement within the VALUE-OF tag. The following text displays the same results as the preceding conditional expression:
Dear <VALUE-OF>if(row["Sex"] == "M"){
Title = "Mr."
}
else{
Title = "Ms."
}</VALUE-OF>
<VALUE-OF>row["Name"]</VALUE-OF>,