Wednesday, December 22, 2010

BI Publisher: Conditional Formatting


Conditional formatting can be used in the layout builder for various scenarios. Some of the scenario I could think of is,
1. Display/hide layout regions based on condition.
2. Display/hide boilerplate text based on condition.
3. Apply visual attributes based on condition.
4. Hide table row or column based on condition.

In the below paragraphs we will see how above scenarios can he achieved in BI Publisher.


When it comes to conditions, obviously its going to be an IF statement just like any other programming language. So here is the syntax of BI Publishers if statement,
<?if:condition?>
…..
<?end if?>


1. Display/hide layout regions based on condition.
By having the condition if and end if before and after the region can either display/hide a region in the template.

image
Same can be achieved using CHOOSE WHEN statement as below,
image
2. Display/hide boilerplate text based on condition.
By using inline if condition we can hide/display a boiler plate text. syntax of inline if statement is,
<?if@inline:condition?>
..
<?end if?>


image
Using inline if condition will avoid getting the hard next line. So that we will get the entire statement in one line or on the same line.

3. Apply visual attributes based on condition.

i) Place the cursor on the table cell on which you want to make the condition.
ii) Select Conditional Format from the BI Publisher toolbar/add Ins of word document.

image

iii) Select the field under the data field box,
image

iv) Enter the condition and click format button to format the text.
image

V) if you like to apply this visual attribute to the entire row, then select the checkbox “Apply to Entire Table Row”
image

Once you apply this conditional formatting you will get some codes getting added as,
<?if:number(SAL)>1000?>
<?attribute@incontext:color;'red'?>
<?end if?>


4. Hide table row or column based on condition.
To hide/display a row based on a condition we just need to add the condition at the beginning and end of the row as shown below,
image


To hide/display a column based on a condition we need @column with the if condition. Just like @inline we used earlier, user @column with the condition on the column you want to hide/display. Syntax,
<?if@column:conition?>
..
<?end if?>



Apart from the above explained if conditions, we have  if-then-else statement, syntax for this statement is,
<?xdofx:if element_condition then result else result2 end if?>