Formatting Maximo BIRT for year end reports

I wrapped up a week long trip to one of our plants to conduct a year end physical count. One change this year has been a request to update the final adjustment summary report. It was requested that our year end reports be an electronic report generated with all the required information in a single PDF document. That sounded pretty simple from the initial description that was given to me. Then a clarification request came in that asked that the title page and the backup data be inside the single document.

That changed things a little bit.

The front page had a lot of boiler plate information that needed to be included, but it required inserting information from the report into the text - total cost of adjustments made, the date the balance reconciliation occurred, number of items counted, etc. Most of the information worked fine until I got to currency values in the text block. I wanted a portion of the text to look like this:

The cycle count adjustments made this period totaled $1,234.56.

But simply inserting the the aggregate summary in the report form ended up looking like this:

The cycle count adjustments made this period totaled $1234.5678.

Not what I wanted at all.

To format the number in the text block too look like it belonged required using some Javascript to reformat the number. I added the following Javascript [1] function to convert the aggregation field from a decimal number to a string with the proper commas and two decimal places. To use this Javascript function in the report, add the function block on the initialize method for the main report design.

function CurrencyFormat(amount) {
    var delimiter = ","; // replace comma if desired
    amount = new String(amount);
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if(isNaN(i)) { return ''; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while(n.length > 3)
        var nn = n.substr(n.length-3);
        n = n.substr(0,n.length-3);
    if(n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if(d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;
    return amount;

The initialize method for the main report would look like this:

By adding it to the initialize method, it allows the Javascript function to be called anywhere in the report. So now the output text in the report I wanted to look like this:

The cycle count adjustments made this period totaled $1,234.56.

Would be entered as a dynamic text object in the BIRT report like this:

'The cycle count adjustments made this period totaled $' + CurrencyFormat(row["aggregate_sum_val"]) + '.';

The boiler plate text is then put into the report header with a page break so it becomes a cover page for the overall report.

So now one BIRT report becomes the cover page and backup details in a single PDF document.

  1. Credit for the Javascript goes to  ↩