Monday, January 24, 2011

BIRT: BIRT Helper Functions

The BIRT Functions provide a wealth of useful functionality that typically gets overlooked by developers. Simple operations such as compares, divides, string functions are handled by these functions with special handling for those really annoying gotchas that are typical.

Consider the following example. Lets say you have a real simple divide expression, such as:

numA / numB

That’s simple enough, right? But that’s assuming that numb is never 0, otherwise you have to worry about the dreaded divide by 0 error. Or better yet, what if one of the values is null because it is not present in the dataset? Normally you would need to change the expression to look like:

if ((numA != null) && (numB > 0))

{

numA / numB

}

else

{

null;

}

But that gets tedious, especially if you have a lot of divide expressions. That’s where the BIRT Functions come into play. In the above scenario, the BirtMath.safeDivide() method can help alleviate the need to do that. So, in the above example, I would basically just use the following:

BirtMath.safeDivide(numA, numB, 0);

BIRT is full of helpful functions such as this, such as Round, RoundUp, RoundDown, different comparison functions, and Date Time functions to work with anything from Years, Quarters, down to seconds. Plus, this functionality is expandable via the BIRT Script Library extension point. I typically recommend that most report writers use these functions in favor of the native Javascript functions.

1 comment:

Spulci said...

I'm just adpating my report using your tips about safeDived eliminating scripting conditions from the dataset.
Thanks a lot!