Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BIRT, How to get Dataset Row Count using Javascript

Tags:

report

birt

How can I get Dataset Row Count from Javascript function in BIRT. I tried searching this in BIRT exchange, but the only solution offered there is to have a new dataset getting count of values of required data set. This wont suit my needs. Is there any way to obtain it using dataset events.

like image 457
Jeevan Kumar Avatar asked Dec 20 '22 04:12

Jeevan Kumar


2 Answers

An easy way would be to count dataset items in a report variable.

  • Declare a new variable in your report outline: enter image description here

  • Reset it in beforeOpen script of the dataset (in case this dataset is invoked multiple times during report execution):

    vars["items"]=0;

  • Increment the variable in onFetch script of the dataset:

    vars["items"]++;

  • Use your variable in any expression. For example add a dynamic text element in report's body such:

    "Items count="+vars["items"]

Important 1: This approach works if and only if the dataset is bound to at least one report element (a table, chart, data element, etc.). For example, it won't work if the dataset is only invoked to fill a list of selection choices of a report parameter.

Important 2: In the body of the report, this variable can only be used after the first report element using the relevant dataset, otherwise it won't be initialized

like image 125
Dominique Avatar answered Jan 13 '23 11:01

Dominique


Dominique has a great answer; It is not clear to me from your question if this simpler solution might also meet your needs.

In your data set use a computed column with a value of '1', then sum the values.

You can write JS that only adds the value if specific criteria are met.

Or you can use an aggregation on your report to sum the values, which would be after any filters or groups are placed.

like image 28
James Jenkins Avatar answered Jan 13 '23 11:01

James Jenkins