Oracle BI Publisher
Oracle BI Publisher
Oracle BI Publisher
- AR_SAMPLE_DATA.xml
- Crosstab_Sample_Data.xml
Before you start the following set of training steps, make sure that you have installed BI Publisher
Desktop Add-in.
Step 2: Insert address block and report level dates and totals
You may want to select single data fields, such as the customer name and address at the header of
the letter. Position the cursor in the Word document where you want to insert the Address. From
the Insert menu select Field… to open the dialog window shown below.
Select the field Customer Name and click Insert to insert a form field for the customer name into the
document. You may also insert the remaining address fields (such as Address Line1, City, State and
Zip). You can also just drag the Customer Name field from the dialog and drop it into the Word
document.
Page 4 of 25
Note: As a beginner, you should use Insert Fields only for data fields that are unique (not repeating)
in your document. Refer to the “Insert Table” section for additional information on how to insert
repetitive fields
From the Preview menu select HTML to preview your template in a browser. From the Preview
menu select PDF to preview your document in Acrobat Reader. You must have Adobe Acrobat
Reader version 5.0 or higher installed to preview documents in PDF format. You can download
Acrobat Reader for free at http://www.adobe.com/products/acrobat/readstep2.html.
The preview should show Vision Corporation instead of the field Customer Name.
The document should include a table of all invoices that are not or only partially paid. On the Insert
menu select Table/Form > Advanced to open the Table/Form Dialog The following dialog will be
displayed:
Scroll in the left Data Source view pane until you see the G Invoices element. Push the left mouse
button and drag the G Invoices element over to the center Template tree view. When you drop an
element with children (other elements below the element), the following pop-up dialog appears:
Page 5 of 25
Note: A Node is a term used in tree views for an element in the tree view. For example,
Customer Name, G Currency and G Invoices are all nodes. Transaction Date is also called a
child node of G Invoices, and G Invoices is referred to as a parent node of Transaction Date.
To add multiple nodes, click Drop All Nodes with the left mouse button. When you select the "G
Invoices" node, the dialog box should now look like this:
We only want to show the fields Trx Number, Trans Type, Transaction Date, Trans Amount, and
Trans Amount Remaining. Select the field Receipt Amount in the center view and press the Delete
button on your keyboard. Repeat the procedure for the other fields that you do not want to be
included in the table (as shown in the screenshot below).
You should now click again on the G Invoices element in the center view. The Properties region on
the right shows how the data fields will be formatted. You should see the following information:
Page 6 of 25
For each group you can set the following properties that describe how a group (such as G Invoices)
should be rendered by the template builder:
Grouping: Grouping is an advanced operation that allows you to re-group the data – for
example by transaction date instead of currency. You can select the element that the data
should be grouped by for this property. Please refer to the Oracle BI Publisher User’s Guide
for additional information on grouping.
Show Grouping Value: This property will only be shown if you have selected a node created
by the Grouping functionality. You can choose for a group if the Data Field node used as a
grouping criterion is shown in the table or form.
Sort By: You can select an element by which the data groups are sorted.
Sort Order: If you have selected an element for Sort By you can select, if the data should be
sorted either ascending or descending.
Sort Data Type: If you have selected an element for Sort By the data is by default sorted as
Text. That means that 12 will be shown after 111. If you need to sort numbers you should
select Number as the sort data type
Break: This property allows you to insert a page break or a section break between every data
group. If nothing is select, then the data groups will be shown continuously with no break. If
you select New Page per Element, then a page break will be inserted between each element.
If you select New Section per Element, a section break will be created for each data group. A
section break allows changing the header/footer and resets the page number. You will
typically use this option, if you want to print multiple documents (for example invoices or
purchase orders) to a single PDF file.
Page 7 of 25
The order in which the data elements are shown reflects the order of the columns in the table. If you
want to reorder the columns you need to change the Insert Position box from Child to Same Level.
Then drag the elements into the correct order.
Click the OK button to create the table. The inserted table should look like this:
Trx Number Trans Type Transaction Date Trans Amount Trans Amount Remaining
for-each TRANS_TYP TRANSACTION_DATE TRANS_AMOUNT TRANS_AMOUNT_REMAINI
G_INVOICES E NG end G_INVOICES
TRX_NUMBER
Form fields representing data elements are replaced with the data when the template is processed.
The for-each G_INVOICES and end G_INVOICES form fields indicate a repeating section. The section
of the document encapsulated by these two form fields is repeated, if the associated data element
G_INVOICE is found repetitively in the data. Please refer to the Oracle BI Publisher User’s Guide for
additional information on form fields.
You can now format these elements in Microsoft Word and add additional text. You can also move
fields around as long as you keep them in the surrounding for-each G_INVOICES and end
G_INVOICES processing instruction. If you remove one of these processing instructions your
template may not work anymore with BI Publisher. You now can preview the template again to
review your current template, this time try PDF as an output.
Number formatting
Select the TRANS_AMOUNT field, right-click and select Properties to see the Text Form Field
Options dialog.
Page 8 of 25
You may select the Number in the Type field, #,##0.00 for Number format and enter 1000 as the
Default Number to achieve a more desirable format for currencies in US Dollar.
Date formatting
To format the date, open the form field dialog for the TRANSACTION_DATE and specify that it is a
Date field. Then select the date format you want to use. It should be noted here that BI Publisher is
expecting the date data as an XSD format date (Canonical Date Format) e.g. 2006-09-01 00:00:00.0.
If the date is not in this format then BI Publisher will be unable to format it further.
Formatting options defined in this dialog box are understood by Oracle BI Publisher and used to
format your fields. Now preview your template again to see the date and number formatting in
action.
Step 6: Dressing Up
You will have noticed by now that you can use the MSWord header and footer functionalities. You
can place a company logo, report title, and page numbering, etc, in the header and in the footer, and
also you can place a BI Publisher’s boilerplates to display data in the header and footer in the
generated reports. Only one problem is that MS Word doesn’t let you place text form fields nor auto
shapes in the area, so if you have such requirements that you need to, for example, display auto
shapes or have conditions that you want to write by using the text form, then you can use BI
Publisher’s tag, <?start:body?> and <?end body?>.
Anything before <?start:body?> tag would be considered as header area and after <?end body?>
would be as footer area, and the between the two tags would be body content area. We will use the
BI Publisher’s header/footer tags for this exercise.
Also it’s a best practice to use a table component to control the layout, so we’ll use a table in the
header section and another table in the footer section.
Page 9 of 25
1. Type <?start:body?> before CUSTOMER_NAME text form. and type <?end body?> after the
table. (You can use a text form to have this tag as well.)
2. Insert a table in the header before the <?start:body?> tag and another table after the <?end
body?> tag. Choose 3 columns and 1 row for the each table.
3. From the right click menu choose ‘Borders and Shading’ and make all the grid and table
frame lines not to be displayed.
4. Type ‘Customer Balance Report’ in the central column of the header table. Make that to be
bold and center alignment.
5. Type ‘Draft’ in the central column of the footer table. Make that to be bold and center
alignment.
CUSTOMER_NAME
ADDRESS_LINE1
CITY, STATE, ZIP
<?end body?>
Draft
Images
It’s a simple case of using the Insert>Picture> From File to insert an image into the header/footer or
main region of the report. Let’s insert Oracle company logo in the header region. You should have
downloaded the file called company_logo.png onto your local machine by now, otherwise download
it from the files online folder.
Page Numbering
You can use the MSWord autotext ‘Page X of Y’ and other auto text objects if you use MSWord’s
native header and footer functionalities. But this time we’re not using that, instead we’re using BI
Publisher’s tags to support the header and footer. But we still can display such page number.
1. Place a cursor into the most right cell and choose ‘Field’ from ‘Insert’ tool bar menu and
select ‘Page’.
2. Type ‘of’ after the ‘Page’ field.
Page 10 of 25
3. Choose ‘Field’ from ‘Insert’ tool bar menu and select ‘NumPages’ and place it right after the
‘of’.
4. Make the cell to be right alignment
CUSTOMER_NAME
ADDRESS_LINE1
CITY, STATE, ZIP
Trx Number Trans Type Transaction Date Trans Amount Trans Amount
Remaining
F TRANS_TYP TRANSACTION_DA TRANS_AMOU TRANS_AMOUNT_
TRX_NUMBE E TE NT REMAININGF
R
<?end body?>
Draft
BI Publisher supports many of the MSWord native functions so spend some time changing the look
and feel of your report using the MSWord dialogs. For example, font size, font color, table color,
table lines, etc, etc…
Adding Total
Now you want to see the total amount of the whole transactions amount. This would be very simple.
1. Click Insert from Template Builder tool bar menu and choose Field
2. Select TRANS_AMOUNT element and choose ‘SUM’ as a calculation
3. Click Insert button
Page 11 of 25
You can add another SUM Total for TRANS_AMOUNT_REMAINING, too. In this tutorial, you’ll add
another row at the last row of the table so that you can display total amount of the whole
transaction at the last row of the table. So it would look like this.
Trx Number Trans Type Transaction Date Trans Amount Trans Amount Remaining
F TRANS_TYPE TRANSACTION_DATE TRANS_AMOUNT TRANS_AMOUNT_REMAINING
TRX_NUMBER E
Total: sum sum
TRANS_AMOUNT TRANS_AMOUNT_REMAINING
In this exercise we also want to display page total, brought forward total and carried forward total of
the transaction amount in each page. The brought forward total is a total amount of the previous
page that is forwarded to the current page while the carried forward total is a total amount of the
current page that is carried to the next page. Since we want to display these total values in every
page, we will put the brought forward total in header area and the carried forward total in footer
area.
Trx Number Trans Type Transaction Date Trans Amount Trans Amount Remaining
F TRANS_TYPE TRANSACTION_DA TRANS_AMOUNT PTTRANS_AMOUNT_REM
TRX_NUMBE TE AINING E
R
Total: sum sum
TRANS_AMOUNT TRANS_AMOUNT_REMAIN
ING
Note that you need to specify a number format in the xdofo tag and MS Word number formatting
functionality can not be used.
1. Insert an additional row under Page Total row in the Footer table
2. Type ‘Carried Forward Total:’ and select right alignment in the central cell of the footer table.
Page 13 of 25
3. Place mouse cursor at the right cell of the table and click ‘Text Form Field’ icon from the tool
bar to insert a Text Form.
4. Double click on the text form and click ‘Add Help Text’ and type the following in the box.
<xdofo:show-carry-forward name="pt" format="99G999G999D00"/>
5. Type ‘Carried Total’ in Default Text field and click OK.
<?start:body?>
Trx Number Trans Type Transaction Date Trans Amount Trans Amount Remaining
F TRANS_TYPE TRANSACTION_DATE TRANS_AMOUNT PT;
TRX_NUMBER TRANS_AMOUNT_REMAINING
E
sum TRANS_AMOUNT_REMAINING
<?end body?>
Page Total: Page Total
Carried Forward Total: Carried Total
Draft
Ok, we’re almost done for this total stuff! Just one more, it’s very exciting one! It’s a running total
that will keep adding the previous value to the current value when it goes down the cells so the very
last value should be the same as a total value. This requires a little trick, so it might sound a bit
complicated, but once you understand it, it’s pretty straight forward! Basically what you need to do
is to define a variable, and add the current value to whatever the value has been added at the
previous cell.
Ok, so hope you can make all the above steps set right, so by this point your report should look like
this.
<?start:body?>
Trx Number Trans Type Transaction Trans Amount Trans Amount Running Total
Date Remaining
F TRANS_TYP TRANSACTI TRANS_AMOU PT; Set999.00E
TRX_NUMBE E ON_DATE NT TRANS_AMOUNT
R _REMAINING
sum TRANS_AMOUNT_REMAINING
<?end body?>
Page Total: Page Total
Carried Forward Total: Carried Total
Draft
<?for-each:G_CUSTOMER?>
As any other programming would do the same, you need to close the for-loop, so you need to insert
another text form field to input the following.
<?end for-each?>
And at this point, having the brought forward and carried forward doesn’t really make sense
anymore, so let’s remove them just to make it simple. So now it should look like the below.
FCUSTOMER_NAME
ADDRESS_LINE1
CITY, STATE, ZIP
Trx Number Trans Type Transaction Date Trans Amount Trans Amount Running Total
Remaining
F TRANS_TYP TRANSACTION_DA TRANS_AMOU PT; Set999.00E
TRX_NUMBE E TE NT TRANS_AMOUNT_
R REMAINING
sum TRANS_AMOUNT_REMAINING
EF
<?end body?>
Draft
However, as you might notice it the page number is still continuous across pages so when you
separate each customer’s document the page number wouldn’t make sense. In order to have
different set of page number for each customer’s document you can use a section break.
Page 16 of 25
1. Double click on the first ‘for-each’ for Customer Name text form.
2. Change the ‘for-each’ loop to ‘for-each@section’
Example:
Before
<?for-each:G_CUSTOMER?>
After
<?for-each@section:G_CUSTOMER?>
3. Click OK.
Try Preview and make sure that your report displays customer data per customer and each customer
section always starts from the top page. Also the page number starts with each customer and the
total number of the pages are the number of pages for each customer’s.
Step:
1. Insert a text form right before TRANS_AMOUNT_REMAINING
2. Double click on the text form
3. Type ‘Red’ as a default text
4. Click ‘Add Help Text..’
5. Insert the following tags.
<?if:TRANS_AMOUNT_REMAINING >100000?>
<xsl:attribute xdofo:ctx="block" name="background-color">red</xsl:attribute>
<?end if?>
This tests the amount remaining value. If it’s over 1,000,000 then the background color attribute is
set to red. This will override any other background color that may have been set.
4. Now test your template using the Preview function and you should see the barcode rendered
based on the data.
This works fine as long as you generate the report on your local machine, but note that it means it
wouldn’t work when you try to generate the report at a different machine unless the barcode font
has been installed and the appropriate font mapping has already been defined. If you need to run
the report at a different machine, for example at a server, which probably would be most of the
cases, then you need to set such font configuration information. We don’t go through that for this
training but you can find the detail information how to set the font information in User’s guide.
1. Double Click on the text form for ‘G_INVOICES’ for-each loop, which is right before
TRX_NUMBER
2. Add the following
<?sort:TRANS_AMOUNT;'ascending';data-type='text'?>
Trx Number Trans Type Transaction Trans Amount Trans Amount Running Total
Date Remaining
F TRANS_TYP TRANSACTI TRANS_AMOU PT; Set999.00E
Page 18 of 25
Trx Number Trans Type Transaction Trans Amount Trans Amount Running Total
Date Remaining
TRX_NUMBE E ON_DATE NT REDTRANS_AMO
R UNT_REMAININ
G
(Double click on ‘F’ text form right before the TRX_NUMBER, you can find the sorting tag.
First, you need to specify on which data you want to sort and select whether ascending or
descending. When you preview at this point you’ll notice that the data is sorted based on the
TRANS_AMOUNT value but it’s not quite right. For example, 120,653.20 is displayed before
12,375.00 although the sorting order should be ascending, which means from the lowest to the
highest. This is because now the sorting is done based on the text value base sorting, not the
number value base. You can change the ‘data-type=’text’ to ‘data-type=’number’, then you’ll see
the data is now sorted by TRANS_AMOUNT number value.
Any content above or below these two tags will appear only on the last page of the report. Also,
note that because this command explicitly specifies the content of the final page, any desired
headers or footers previously defined for the report must be reinserted on the last page.
<?start@last-page:body?>
<?end body?>
7. Copy the header and footer content from the first page and paste them to each of the
header and footer area in the second page.
8. Click ‘Insert’ from Template Builder menu and select ‘Field’.
9. Select ‘Trans Amount Remaining’ from the tree and choose ‘SUM’ from the calculation LOV,
and click ‘Insert’ button, so that you have the sum of Trans Amount Remaining in the right
cell right after ‘Remaining Transaction Amount Total:’
10. Try Preview to see the result
Page 19 of 25
You will notice that all the pages show total amount of Trans Amount Remaining in the footer area
except for the first page for the customer that goes across more than one page. For example, look at
a customer, Computer Service and Rentals, which has 2 pages of the report. You’ll see that there is
no Trans Amount Remaining total displayed in the footer area in the first page and only the second
page has the Trans Amount Remaining total displayed in the footer. That’s what we are talking
about! ;-)
Before you start the following steps, you need to take the section break out from the ‘for-
each@section’, which you have done it at Step 11.
After you click ‘OK’ you’ll see a dummy image inserted in your report. At this point, the image
doesn’t show the data in the Graph plot area though Customer names are displayed correctly. This is
because inside the chart XSL definition the XPATH for TRANS_AMOUNT element is not set
appropriately. Follow the following steps to modify the XSL definition.
<Cell>
<xsl:value-of select="sum(current-group()/TRANS_AMOUNT)"/>
</Cell>
4. Change it to
<Cell>
<xsl:value-of select="sum(current-group()//TRANS_AMOUNT)"/>
</Cell>
Try preview you’ll see the bar graph will be displayed with actual values.
Example:
Page 21 of 25
You can also try different type of charts by using the Chart Creation Tool of the template builder.
There are whole a lot of different types of graphs are supported as long as BI Beans supports, but
you need to understand the Graph XML and Data XML definition, you can find more information on
BI Beans web site.
Ok, we’re almost done, all the contents are presented. But at the last thing, let’s master this very
cool technique that would attracts a lot of people! It’s Table of Contents and Bookmark!
Table of Contents
This is pretty easy and very straightforward. What you need to do is just to use MS Word native
function.
1. Type <?CUSTOMER_NAME?> and remove CUSTOMER_NAME text form, this is because the
Table of Content function can not handle the text form.
2. Change the font setting for the <?CUSTOMER_NAME?> to be ‘Heading 1’.
3. Insert a section break before the first page header so that you will have a blank page as the
first page. You can use MS Word’s section break for this. (Insert->Break->Section Break->Next
Page)
4. Move to the inserted first page and place your mouse cursor into the first page.
5. Click Insert from the tool menu and select Reference-> Index and Tables
6. Click Table of Content tab and choose how you want to display your Table of Contents
7. Click OK.
8. Make sure that the table of contents has <?CUSTOMER_NAME?> tag inserted.
So, you should see something like the following in the first page.
Page 22 of 25
As one of new features that have been introduced with 10.1.3.2 is a Crosstab support through
Template Builder. Before, you still could create a crosstab, but you need to develop some logic to
support dynamically generating columns and cells. Yes, if you have been there you know what I’m
talking about… It was a lot of pain! But now, you can just insert the crosstab from the Template
Builder tool bar and map required element in the UI, and you have the crosstab in your template!
It’s nothing!
In order to play with the crosstab, let’s start with a new data and new template.
Bookmark
So the one last step! Now you have a table of contents displayed in the first page and sometimes
that is what users want. But if you’re familiar with PDF document you might want to make it as a
bookmark that is displayed at left pane and makes so easy to move around the document you
generate. Only you need to do is to add BI Publisher’s tag before and after the table of contents that
has been added at the previous step.
Page 23 of 25
1. Remove the section break that has been used to create the first page for the table of
contents because the table of contents is not going to be displayed, it will be converted to a
bookmark, so you don’t want to have one blank page at the first page.
2. Add the following tag before the table of contents.
<?convert-to-bookmark:?>
3. Add the following tag after the table of contents.
<?end convert-to-bookmark:?>
Now, try preview the document, you will see a bookmark that has links to each customer’s report.
Pretty cool, huh?!
Before this exercise let’s create a new template and load a new data for crosstab layout.
Page 24 of 25
1. Create a new RTF template
2. Load Crosstab_Sample_Data.xml
3. Go to File->Page Setup and choose Landscape as Orientation
4. Select Crosstab from the Template Builder tool bar. (Insert->Crosstab)
5. Drag and Drop ‘Flows’to data area
6. Drag and Drop ‘Bus Grp’ to Row Header area
7. Drag and Drop ‘Type’ to Column Header area
8. Click OK.
Now when you try preview it, you’ll get a crosstab layout report!
As you notice there are many text forms inserted along with the creation of crosstab.
Basically, the first row is displaying column header by having for-each-group loop with ‘Type’
element. And then the row header of the second row is taking care of repeating Business Groups in
vertical order with for-each-group loop logic. And inside the for-each-group logic there is a for-each-
group loop logic, which you can find it in the second cell from the left in the second row. And the last
cell in the second row is talking care of sub-total, which is a total for the Business Group in the row.
Lastly, the last row is similar to the first row, but the difference is to display total for each Type
column. So now you know what I was talking about! Yes, you had to do this by yourself before, old
days….. But now you don’t really need to think about the logic, you can create the crosstab in just a
matter of 5 seconds!
Conclusion
Now you have finished all the steps and should have this fancy customer balance report that has
implemented many techniques of BI Publisher and MS Word. With all the steps done with this
tutorial you should be able to develop many different varieties of BI Publisher reports and also
Page 25 of 25
should be able to demonstrate its strong capability and flexibility to satisfy many different business
requirements on business report. Also with this tutorial and materials along with this training you
should be confident enough to provide a training of RTF template development to somebody else.
There are more RTF template development techniques, so keep play around with BI Publisher and
you will find more fun and excitement! Have fun!