If-then-else Statements in BI Publisher

Today I find myself with the tedious task of converting Crystal Reports to BI/XML Publisher.  At one point I found it necessary to add a conditional statement to the report.  I attempted to use the BI Publisher tool in Word and add a ‘conditional region’.  It would have worked fine had I pursued that route, but after fiddling with the second field I realized that the maintenance involved with the 10 or so conditionals included in the report would have been too much to handle.  Not only that, but I had a few else clauses that the ‘Conditional Region’ can not handle at all.  After scouring the web for a solution, I ran into a few articles that discssed the Extended Function Support in RTF Documents (xdofx) in a BI publisher report.  Thought I’d give it a try.

The format of an xdofx if-then-else is:

<?xdofx: if <condition> then <statement> else <statement2> end if?>

simple enough, but where to put it?  The answer: Anywhere!

This wonderful piece of code can appear anywhere in the RTF Word document and it will be executed properly when BI Publisher runs.  This however can make the document extremely messy.  I came up with a cleaner solution.  The advanced tab on a field.

When inserting a field using the BI Publisher add-in on Word, one can insert a simple field onto the document.  The option of formatting makes it easy to make your report presentable.  The advanced tab is there if you need something more complex.  That’s where the xdofx code comes in.  I was able to successfully put an if-then-else-if statement with some complex logic and there were no problems when it ran.  The best part is that it compresses all the code and formatting into a small placeholder packet on the document.  No messy code, no ugly documents.xdofx code

In this particular instance, the result returned from the if statement (Monetary_amount) needs to be formatted.  Rather than have more messy code, after typing the if statement, I switch back to the properties tab and set the format to any of the pre-defined formats.

A wonderful solution for my problem and an amazing timesaver.

 

Leave a Reply

Your email address will not be published. Required fields are marked *