Creating a Row Number in a Grouped Detail

I've been working on a way to review with my power users how they've setup their Start Centers. The goal was to ensure suggested Start Center setups were in place and to see if any custom setups should be shared with other sites. This required getting a snapshot of what they setup in their Start Center before meeting with them. The hard way was asking for everyone to take a screenshot of their Start Center. The easy way was creating a report to show what was in a user's Start Center.

I got the report drafted up fairly quickly and it looks like this:

A problem I ran into was a text label I wanted to use - "Fields in Result Set" - in the detail row. The idea was to insert a text element and then suppress it after the first row. The problem was the text label is in a detail row of a grouped field (the gray background/white text sections) and the row numbers reset on the table, not the group, in BIRT.

Setting up the report

The report needed the ability to have the equivalent of the row.__rownum function, but count and reset on each Group heading. Once the row count function was working, I could use it suppress the extra text labels. In the end this report demonstrated a unique combination of two setups:

  1. Creating a row count under a Grouped field.
  2. Using the new functionality to suppress information in the report.

Set variable on initialize script

The first step is to declare the variable for the detail row number. To do this you need to add the variable on the overall report initialize script page. In this case the the variable declared is: rowCount = 0;.

Set the variable on Group onCreate script method

The next step is to place the variable on the group. This doesn't actually set the variable, but resets the value of the rowCount variable back to zero (0) for each group. If this isn't set on the Group, the rowCount variable would continue to increment like the native row.__rownum function.

Increment the rowCount on Detail onCreate script method

The next step is to place an increment operator on the rowCount variable to ratchet up the counter for each detail record. Add the rowCount the variable on the Detail onCreate script method using the ++ operator.

Verify the rowCount function is working

After doing the previous steps, double check that the rowCount variable is incrementing as planned. Insert a Dynamic Text element and inside the element enter the rowCount variable.

Now do a preview to see if the row count is resetting for each group.

Set Visibility on the text element

With the row counting working as planned, use the variable on the visibility of the text label. Open the Properties of the text element and set the visibility to rowCount > 1.

Final Results

With everything in place, the final results look like this:

The text element will now show up only on the first line in the detail row.

Comments

Top