BIRT, How to get Dataset Row Count using Javascript

Jeevan Kumar picture Jeevan Kumar · Apr 21, 2015 · Viewed 8.6k times · Source

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.

Answer

Dominique picture Dominique · Apr 21, 2015

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