Getting multiple values from a data set to use as parameters in a BIRT report

Options
mogwai
edited February 11, 2022 in Analytics #1

I have a data set with a known number of rows like this:
Name Value
Cutoff 1 20
Cutoff 2 25
Cutoff 3 30

Now I would like to get these values (20, 25, 30) into parameters (cutOff1, cutOff2, cutOff3) that I can use in expression builders in tables and crosstabs. Any ideas?

Best Answer

  • mogwai
    #2 Answer ✓
    Options

    Hi Chad,

    I think your solution will work but because I need to bind the data set to a table anyway, I came up with the following solution, which essentially does the same:
    In the detail row of the table I put a data binding with the following expression:
    vars[row["property_name"]]=row["property_value"];

    This after manually creating the 4 variables I needed, with known names (the values of the column property_name). The table is hidden since I don't need it.

    Thanks for your help Scott and Chad.

Answers

  • Good morning! I think you're trying to do what is shown in the screen cap:

    You said you have a known number of rows, but does the 'Value' column change? If it does, then you would use the 'Dynamic' population of the list (I used a query in the Scrap_Type data set that basically grabs all distinct values in the scrap_type column). Otherwise, you could just use the Static value, and manually type them in.

    Hope this helps.

    If you need more detail, let me know. If this isn't what you're seeking, I apologize.

    Have a great day!

    Scott

  • Hi Scott,

    The solution you are suggesting will provide a select list based on the values in the table, of which I can select one when running the report.
    I don't really need a parameter - rather 3 global variables that are automatically populated from the 3 rows in the table. I need to be able to use all three values in tables and cross-tabs in the report

    Thanks,
    Miguel.

  • Miguel,

    Good morning! So, possibly this is what you are looking for:

    vars["x1"] = this.getRowData().getColumnValue("y1");
    vars["x2"] = this.getRowData().getColumnValue("y2");
    vars["x3"] = this.getRowData().getColumnValue("y3");

    I have something similar to this in one of my reports. The script is in the 'onCreate' of the table.

    Have a great day!

    Scott

  • Getting there, but this appears to get the values from three different columns of the first row of the data set. I need something like this:
    vars["addaSusceptible"]=this.getRowData().getColumnValue("property_value");
    vars["lddaSusceptible"]=this.getRowData().getColumnValue("property_value");
    vars["lddaResistant"]=this.getRowData().getColumnValue("property_value");
    vars["addaResistant"]=this.getRowData().getColumnValue("property_value");

    Where each consecutive variable is populated from the same column of consecutive rows.

  • Your best bet most likely is to use the onFetch event of the data set. It kicks off for every row returned from the data set, so you can do something like myVar = row["Value"]. You would need to have some kind of check, either by row number, or looking at a value in another column, to assign the value from each row to a different variable/parameter.

    Note that onFetch only runs when the data set is needed. So it would need to be bound to a table or something. Alternatively, later versions of commercial BIRT have a built in function to force a data set to run, and returns an array of objects that you could parse through.

    Warning No formatter is installed for the format ipb
  • mogwai
    #8 Answer ✓
    Options

    Hi Chad,

    I think your solution will work but because I need to bind the data set to a table anyway, I came up with the following solution, which essentially does the same:
    In the detail row of the table I put a data binding with the following expression:
    vars[row["property_name"]]=row["property_value"];

    This after manually creating the 4 variables I needed, with known names (the values of the column property_name). The table is hidden since I don't need it.

    Thanks for your help Scott and Chad.