Friday, August 21, 2015

Formatting Rich Text Comments in BI Publisher

In the last years, BI Publisher has become the go to tool to cover most reporting needs in PeopleSoft, replacing other technologies such as Crystal Reports and SQR in many scenarios.



The basic concept behind many reporting tools is separating data and presentation logic, so report designers can work in parallel with developers who know the data model in detail. BI Publisher is the PeopleSoft reporting tool that achieves this separation in a more thorough way. It does so by using XML as the information exchange format between the data generation and the report generator. Practically all systems have a way to export data in XML nowadays, and PeopleSoft is not the exception, with options ranging from Connected Queries, File Layouts to PeopleCode managed XMLDocs. From my point of view, this is major advantage over other technologies like Crystal Reports, which in its PeopleSoft version could only extract data from PeopleSoft queries (if you needed to extract somehow complex information, you would need to create an extraction program).

Other advantages of BI Publisher are the bursting capabilities (separating report output based on certain data fields) and the possibility to generate online reports without using Process Scheduler.

Formatting Rich Text Fields

I have to admit that I'm far from being a reporting expert, but in one of my latest projects I came accross the need to develop several of them. One of these reports needed to display comments previously entered by users in rich text format. BI Publisher provides a function to do so:
<?html2fo:elementname?>
However, this function has a problem I was not able to solve (I admit there could be other solutions but I could not find anything as part of my research in a few forums): if you are building a report with certain style guidelines, the rich text would always be rendered using Arial 12pt as the base font. This resulted in a very funny looking report, with large fonts coexisting with smaller ones. Of course, there was the option to also use Arial 12pt as the report base font, but users are not always ready to change their aesthetic requirements.

In the end, we found out that the html2fo function would render the rich text using the inline style of HTML elements. PeopleSoft normally does not set a font-family nor font-weight (please check the note at the end of the document), so BI Publisher automatically applies the default style, which is Arial 12pt. However if you set the style be yourself, BI Publisher would accept it.

The following code shows an extract of how we set this style:

Function FormatRichTextForBIP(&text As string, &fontSize As string) Returns string;
   Local string &result;
   
   If All(&fontSize) Then
      &result = "<div style='font-family: verdana;font-size: " | &fontSize | ";'>" | &text | "</div>";
   Else
      &result = "<div style='font-family: verdana;'>" | &text | "</div>";
   End-If;
   
   Return &result;
End-Function;


(...)
&reportingRec.COMMENTS.Value = FormatRichTextField(&inputRec.COMMENTS.Value, "12pt");
(...)

Note: This approach would not work if within the rich text the user has included different font sizes. This basic approach works when no font-family or font-weights are applied within the stored rich text HTML. In any case, this is a solvable issue, although it may require some more work. What you need to do is parse the rich text and replace the desired style clauses.

3 comments:

Spark said...

We have the same issue with PeopleSoft ePerformance document. Where should I put the code you provided?

Thanks.

Javier Delgado said...

Hi Spark

You should check where in the PeopleCode that generates the report is the Rich Text field populated. There should be the place where you can use the code in the article.

Thanks

Matthew Raffel said...

Thank you Javier. Worked on the first attempt. Was playing around for days trying to get the HTML_SUB Sub-Template Oracle suggests to work.