0

I'm developing a BIRT report and this is my situation. I have one text element, let's say this:

blue square: 111
blue triangle: 222
red circle: 333

At the moment is static, and always displays the numbers you see. I would like to make the numbers dynamic so I created a SQL query and I have embedded it in a dataset. Let's say this is the output:

color        shape     count
blue         square    123
red          circle    456
blue         triangle  789

I would like to set it up in such a way that each data set row matches the correct row in the text file, so it would become:

blue square: 123
blue triangle: 456
red circle: 789

And will be automatically updated.

I've binded the text element with the dataset and wrote this as a test:

blue square: <VALUE-OF>if (row["color"].toUpperCase() == "BLUE") { row["count"] }</VALUE-OF>
blue triangle: 222
red circle: 333

But when I run the report it doesn't work and the value is blank. What am I doing wrong?

Thank you all for the help and let me know if you need more info.

jackscorrow
  • 682
  • 1
  • 9
  • 27

1 Answers1

0

You now have a dataset with row[color], row[shape], row[count] to simplify your desired output I would add a "computed column" to your dataset.
e.g. row[output] = row[color] + ' ' + row[shape] + ': ' row[count]

Once you added the computed column just drag and drop your dataset into your report (where you now have the text element) and delete the unused columns.

Tip: if don't know "computed columns":
  use Google image search for "bird computed column example"
  the Google text search might get you lost in birt forum lists.

Update: It’s possible you have some typo in your scriptlet. In BIRT a scriptlet resolves to the last expression within itself. Your scrptlet <VALUE-OF>if (foo) { bar }</VALUE-OF> doesn’t have a last expression.
(It's not wrong but BIRT may not "understand" it this way)
Try instead <VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF> and format the scriptlet to several code lines with result; as last line. This is the same as if we consider the scriptlet as a function in some programming language and the last line of the function would be return result.

bw_üezi
  • 4,483
  • 4
  • 23
  • 41
  • Unfortunately this is not an option. The one I have here is just an example to better understand the problem, but in my real case I can't reproduce the entire row using a data set. I need to insert specific parts of a data set inside a paragraph of text – jackscorrow Nov 24 '20 at 09:17
  • @jackscorrow: the point is is that the computed column is whatever you want it to be. It's only the same as the entire row in your basic example here. With a computed column you create one (or more) additional column in your dataset that contain exactly that subset data that you want – bw_üezi Nov 28 '20 at 00:06
  • but I could achieve the same thing by editing the SQL query underneath. I wanted to understand if it was possible to access a dataset using both row and column identifiers instead of just column. This would make things easier instead of computing additional columns or complicate the SQL query underneath. Not sure if I'm explaining myself correctly... – jackscorrow Nov 30 '20 at 16:25
  • Yes, „complicate” the SQL is also possible. I wouldn’t consider this as best practice either. – bw_üezi Nov 30 '20 at 18:00