A hidden gem in XML—row level formatting

As you know now, a Cognos Report is an XML definition. When you create or update a report in Report Studio, the corresponding XML tags are added to or modified in the report specification. However, it is possible to directly add or modify XML tags that are not visible from the studio as an object or property.

In this recipe, we will see how to define crosstab row level formatting in the XML to save the development and maintenance time.

There is a crosstab report with many measures on columns. The business wants to highlight the rows which belong to costly products (>25 units). Instead of defining conditional formatting for every column, we will modify the XML here to directly define row level formatting.

Getting ready

Create a report with product name on rows and various measures on columns, shown as follows:

Getting ready

How to do it...

  1. Define a conditional variable of Boolean type to identify costly products (which are to be highlighted in the report).
    How to do it...

    Call this variable as Is_Costly.

  2. Now select the first column Quantity. Attach the conditional variable Is_Costly to it as Style variable. Define the appropriate formatting for this column for both the conditions (Yes and No). We have already talked about defining conditional styles in prior chapters.
  3. Now copy the report to clipboard and paste in a new file in an XML editor. I have used Visual Studio for this purpose.
  4. Run a search for <conditionalStyles> tag. You will find this element under Quantity data item.
  5. Copy the whole element, that is from <conditionalStyles> to </conditionalStyles>.
    How to do it...
  6. Now locate the <crosstabRows> element. You will see that it has a <crosstabNodeMember> defined for product name.
    How to do it...
  7. Replace the empty <factCell/> with the following code:
    <factCell>
    </factCell>
    
  8. Now paste the <conditionalStyles> tag copied in step 5 within the <factCell> element. The code will now look like this.
    How to do it...
  9. Copy the whole XML back on clipboard and open in Report Studio.
  10. Run the report to test it.
    How to do it...

As you can see, the whole row is formatted based on the condition.

How it works...

In Report Studio, there is no option to select and modify whole row in crosstab. Hence, if we want to do any row level formatting, we need to do it for each column.

However, if you examine the report XML, you will notice that it has an element for fact cells under crosstab rows. Here we are overriding this element and defining our own style to be applied for every fact cell within that row.

Instead of manually writing the whole conditional style code, we have first applied Conditional style on one column (quantity) and then copied the same under "Crosstab rows" so that it is applied on all the columns.

There's more...

This recipe will save your development time as you don't have to define the conditional styling for every column. Also, in future if styling needs to be changed, it can be changed from just one place than doing so for every column. Hence, it will save maintenance time as well.

You can also experiment with the <crosstabColumns> tag to style whole column, when there are multiple members on rows.

See also

For conditional formatting basics, please refer to Chapter 1, Report Authoring Basic Concepts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset