Windward DocumentationWindward DesignerDesigner for Microsoft Office FAQsHow Do I Create a Custom Windward Function for the Java Report Engine?

How Do I Create a Custom Windward Function for the Java Report Engine?

The Java Report Engine (the Engine) ships with many functions, however, you may find from time to time you require a function customized to your needs that does not exist in our library. The Engine allows you to define your own custom macro functions to expand the Windward reporting functionality.

In this article we'll work step by step through a Catapult Java Report Engine custom function example. We'll create a function "E()", which returns the first 15 digits of the value of Euler's Constant e.

Create the Custom Function

Open Catapult. (Found under Start -> Windward Studios -> Catapult - Windward Java Engine Demos) and click the JAVA button.

Under Java Demos, click on the Specialized button.

Scroll to the right and click on the Custom Functions button.

Windows Explorer will open the directory where the custom function Java Report Engine demo is installed, by default "C:\Users\%USERNAME%\Documents\Windward Java Engine Samples\Java\Specialized\CustomFunction". After Windows Explorer opens, start IntelliJ IDEA by double-clicking on the file CustomFunctionExample.ipr.

IntelliJ IDEA starts with the file open. In that file you can write custom functions to use with the Java Report Engine. We have provided three custom functions: PI(); SQRT();  and MULTIPLYALL(). Now we'll edit to add our new custom function E().

First, change the number of functions to 4. 

Paste this code into the second section (below MULTIPLYALL()) to add some metadata for the new custom function:

functionName[3] = "E";
functionFullName[3] = "E()";
functionDescription[3] = "Returns the value of e, 2.71828182845904, accurate to 15 digits.";
functionNumberOfArgument[3] = new Integer(0);
functionArgumentName[3] = null;
functionArgumentDescription[3] = null;
functionArgumentType[3] = null;

Paste this code into the fifth section (below MULTIPLYALL()) to add the function definition itself: 

public static Object E() {
      return new Double(2.71828182845904);

Finally, click on Build, then select Rebuild Project.

A notification in the message bar at the bottom of IntelliJ IDEA indicates the build was successful.

Install the Custom Function

The result of the steps above is to create a new WindwardCustomFunctions.jar file. Now we need to install that file so the Java Report Engine will use it.

Click on the Custom Functions button in Catapult again to open Windows Explorer on the Custom Functions Java Report Engine demo directory.

Navigate to out\, artifacts\ then  WindwardCustomFunctions\.

Copy WindwardCustomFunctions.jar. Then navigate to the installation directory of the Java Report Engine, by default "C:\Program Files (x86)\Windward Studios\Windward Java Engine."

Open the jars\ directory and paste the new WindwardCustomFunctions.jar, overwriting the old one.

Now the custom function E() is available when generating output with the Java Report Engine.