Monday 31 March 2014

BI Publisher Sub templates and calling them conditionally

I had a few issues today that sent me off on an oddesy to learn about sub templates and how to use them . and now I've had a fiddle with them they have totally revised my approach to writing templates.  there really dead useful :).

 I'm working on one of our company invoices and  was having quite an unpleasant time trying to work out how the hell to make this template work . like every one else out there I should imagine our invoices can have  lots of different ways to display a line item and you can have any number of line items on a page how on earth was I going to cope with invoices that went over to more than one page ?????   this is the type of thing that on more than one ocasion has reduced me and Mike to sobbing wrecks and reaching for the poultry with one hand and the Whisky with the other when we tried to do this with transform

dead easy it turns out.

This where sub templates come in .  Sub templates are small templates in there own right that you can either store in another RTF document  or stick at the bottom of your template out of the way (which is what i did  in this case) 

My first issue was to make sure the header and footer on each page were there and displayed properly . I  had one header section which is displayed on every page  and 2 footers. one which is displayed on the last page  and one  on all the others . so I created these  as sub templates.  to do that i just wrapped them in <?Template:?> tags  like this 













then i just popped <?call-Template: PageHeadder?> in the  header of my word RTF Template. 

Next I tackled the footer issue by doing exactly the same I created 2 Templates  a page footer one and an last page footer one  then used a choose statement to choose which one to display in the footer  using a bit of code like this 

<?choose:?>
          <?when:PrintTax_ID5=“Y“?><?call:PageFooterWithTax?><?end when?>
           <?otherwise:?><?call:PageFooterNoTax?><?end otherwise?>
<?end choose?>


finally I created a sub template for each of the different line types i had  and used exactly the same technique to call the sub template for the line type i wanted to display .  yet again  no swearing sobbing or poultry bothering required 

Wednesday 19 March 2014

BI Publisher Storeing a substring of an XML tag into a variable

this gave me a bit of  a headache  I had a task where i needed to chop of the last  character of one of the XML tags so I could use it in some of the logic statements  further down in the code  .  this did the trick  OptioPrinterName_ID180  is the name of the XML tag i wanted to chop the end off and store  and 1 at the end  is the number of characters to chop


<?xdoxslt:set_variable($_XDOCTX, ‘optioChar’,xdoxslt:right(OptioPrinterName_ID180,1))?> 

 Then further down in the code when i needed  to reference the variable for my logic  i Referenced it as follows


<?choose:?>
         <?when:xdoxslt:get_variable($_XDOCTX, ‘optioChar’)=‘A‘?>Test<?end when?>
           <?otherwise:?>Test2<?end otherwise?>
<?end choose?>

Tuesday 18 March 2014

BI Publisher Conditional Character Spacing on a Field

I have just come across an interesting issue  that took a little bit of brain scrambling to sort out.  I had a field that I had to display in two different ways 

 if the field was on the last page of my document I needed to display the date  with 2 spaces between each of the characters   a bit like 1  8  0  3  2  0  1  4

for any other page i had to display     "***VOID***" with normal spacing.

now id managed to get my if statement working fine  to display eather the date or void but the spacing issue became a major headache.

i tried all sorts of XSL_FO combinations to no avail  them a eureka moment .  I could add two fields . id use word to increase the character spacing on one field   and leave the second field with normal spacing.

in the absence of discovering a better way to do it all in one field (Hope fully some one more experienced can sugest that)  hers the code in my feilds  that i used to resolve the issue


word field formatted to double space the chars 
<?xdoxslt:ifelse(Current_stub_number___Local_ID46 !=  Stub_Total___Local_ID66, '' ,G_L_Date2___Local_ID64)?>


second word field formatted as normal 
<?xdoxslt:ifelse(Current_stub_number___Local_ID46 !=  Stub_Total___Local_ID66, ' * * * VOID * * * ' ,'')?>


to increase the spacing on the first field  clicking on the little arrow at the bottom of the font  ribbon brings up the following where you can  increase and decrease character spacing over a field paragraph etc etc in word


so eather the single spaced or the double spaced field is shown 

Extended Function Support in RTF templates BI Publisher

ok while hunting round the interwebz for a way of taking a date and turning it into a sub string a character at a time  (don't ask its a finance report thing  SHUDDER !)  I stumbled across this incredibly cool Oracle document  that shows loads of SQL , XSL, and FO elements and functions and how to do them in BI Publisher  well cool and extremely Useful  thank you Oracle   thank you Oracle Techno Pixies :)


extremely cool  and useful Linky

Friday 14 March 2014

Using a Case statement in BI Publisher

This is really useful  and surprisingly easy   if you need to display multiple different pieces of information   on part of the document that depend on a value or values in  the XML  you can use a load of  "if"  or "if:else"  statements   but its much easier neater and more brain friendly to use a case statement like the following

where Company_ID199   is the tag in The tag in the XML that you want to make the decision based on


<?choose:?>
             <?when:Company_ID199=‘00040‘?>Test <?end when?>
             <?when:Company_ID199=‘00041‘?>Test 2<?end when?>
             <?otherwise:?> Test3<?end otherwise?> 
<?end choose?>

Wednesday 12 March 2014

Conditional Sections In BI Publisher

One issue that was always a major headache for us with Transform was the Terms and Conditions pages which are attached to the end of all our sales documents .  when ever there was an update to the T&C's we would have to slog through each of the sales documents to see which copy of the T&C's it was calling and then do it all over again for the copies in french . Frustrating  as I'm sure you can imagine .

So to get around all that we decided to just have one T&C's document and add it as a second template to the report definitions . that way we only ever need to update one document . but we did have to build in some conditional logic to display the different sections of the T&C's in English and french.  to do that we used Conditional Regions.   these are great you rap a paragraph or a table  or what ever you fancy in some conditional code and it either displays or dosent depending on the logic in the conditional statement the following explains it really well and is shamelessly pilfered from some of the oracle documentation

11.4.5 Inserting and Editing Conditional Regions

A conditional region is an area that is surrounded by a conditional statement. If the statement tests true, the area is displayed in the report; if the condition tests false, the area is suppressed from the report.
For example, your data contains salary and position information for all employees. Your report contains a table that displays the employee, position, and salary. You want your report to display salary information for managers only. Using the insert conditional region functionality, you can select the region that contains the employee table and insert the condition that the position element must equal manager.
To insert a conditional region:

  1. Select the region that you want to apply the condition to. For example, if you want to display a table only for a certain condition, select the region that contains the table. Note that the region must be inside a loop.
  2. From the BI Publisher toolbar select Insert, then Conditional Region.
    The following figure shows the Conditional Region dialog:
    This image is an example of the Conditional Region dialog.
  3. Enter the following fields:
    • Data field - Select the field to test for the condition.
    • Select the data type of the field: Number or Date/Text.
    • Select the comparison operator for the data field. Options are:
      • Equal to
      • Not equal to
      • Greater than
      • Less than
      • Greater than or equal to
      • Less than or equal to
      • Enter the value to define the condition, or select from the list of data elements to define a conditional relationship based on the value of another data element.

Getting BI Publisher to print out multiple copies based on a value in the XML



I found a few pages with descriptions on how to do this but none were particularly clear so for the sake of my and Mikes Sanity ive made a simpler example using one of our reports 

 you put the whole template page inside a double for each loop like this  

the green highlighted bit is the full path to the xml field holding the number of copies  
(the +1 ive highlighted in yellow is in  there because the number of copies in the XML i was using  is set to zero its a number of ADDITIONAL copies field  hence the plus 1 :)  you wouldent normally need that bit   )  .  

and you need to add the second for each loop to say  go of and do everything on the report

<?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,/R42530V/DETAIL_1_S4_Group/Total_1_S7/On_Ship_To_Connect_to_Level_Break_S5/NbrOfCopies_ID150 + 1,1)?> 

                 <?for-each:/R42530V?>
                         //  The rest of the Template goes in here //
                <?end for-each?>

<?end for-each?>