Chapter 7. Elixir Report Designer JavaScript Reference

Table of Contents

JavaScript API Reference
Elixir Utility Functions
Utility Objects
Data Objects
Raw Report Objects
Logical Report Objects

JavaScript API Reference

Each object is described in terms of functions and properties. The Property identifier is used to indicate the ability to both get and set a value. For example,

Property: A : String

indicates that the object has both String getA() and void setA(String a) functions. If the return type is a Boolean, then the naming follows the Java convention of using "is" in place of "get" - Boolean isA and void setA(Boolean a).

Where objects are identified as X extends Y, this indicates that all functions of Y are applicable to each X object.

Where colours are required to be provided as Strings, Elixir Report Designer supports all CSS standard names, including: "Black", "Blue", "Cyan", "Magenta", etc. See Figure 4.2, “Named Colours” for a complete list.

this.setBackgroundColor("Red");

Alternatively, an RGB value may be supplied, with an optional alpha transparency value. Values should be in the range 0-255:

this.setBackgroundColor("rgb(255,0,0)"); // red,green,blue
this.setBackgroundColor("rgb(255,0,0,128)"); // red,green,blue,alpha

Elixir Utility Functions

To avoid possible conflicts with other libraries in future, these functions which were previously global, have been moved to a namespace elxfn. For backwards compatibility they are still also provided as global functions, but these will eventually be withdrawn. A JavaScript warning will be logged for each use of a deprecated function.

Table 7.1. Core Object, Number and String functions

  • Boolean elxfn.isNull(a)

  • Boolean elxfn.isNumber(a)

  • Boolean elxfn.isString(a)

  • Boolean elxfn.isDateString(str,pattern)

    The pattern parameter is optional, the default is "yyyy-MM-dd" if it is not defined.

  • Boolean elxfn.isNumberString(str)

    Indicates whether a given string contains a valid number (parsed by Java). An alternative pure JavaScript approach is to use "new Number(str)!=NaN".

  • Number elxfn.asNumber(str)

  • String elxfn.trim(str)

  • String elxfn.strip(str, ch)

  • String elxfn.leftTrim(str)

  • String elxfn.rightTrim(str)

  • String elxfn.terminate(code,message)

    The terminate function provides a scripted way to abort report rendering. For example, if you want the report to only render when there are data records available, you can add a script to the first Section Header OnRenderBegin:

    if (Data.getRecordCount()==0) 
        elxfn.terminate(101,"No records available");

    Elixir Repertoire Server 8.5.0 enables both the status code and the exception message to be passed back to the caller though the JobInfo. As in the example above, the user will receive a custom message in the API software, saying "Status Code: 101, Exception Message: 101: No records available". Values less than 100 are reserved for internal use. You could also use terminate to test for valid combinations of parameters.

    To configure the status code and exception message, refer to Elixir Repertoire Server User Manual > Chapter 7. Elixir Repertoire Server Client > Java Standalone Clients > Code example > Configuring custom status code and exception message.

Table 7.2. Date functions

  • Date elxfn.offsetDays(origDate, numDays)

  • Date elxfn.offsetMonths(origDate, numMonths)

  • Date elxfn.offsetYears(origDate, numYears)

  • Date elxfn.offsetDate(origDate, numYears, numMonths, numDays)

  • Number elxfn.dateDiff(DateA, DateB, interval)

The allowed interval values for dateDiff are: "s","m","h","d" (seconds,minutes,hours and days).

Utility Objects

Table 7.3. Format

The Format object provides functions for manipulating and formatting text. The pattern definitions are described in the Java API.

  • String padLeftAligned(String s,int width)

  • String padRightAligned(String s,int width)

  • String padCenterAligned(String s,int width)

  • String spaces(int len)

  • String formatNumber(Number n, int decimalPlaces)

  • String formatNumber(Number n, int decimalPlaces, String locale)

  • String formatNumber(Number n, String pattern)

  • String formatCurrency(Number n)

  • String formatCurrency(Number n, String locale)

  • String formatPercent(Number n, int decimalPlaces)

  • String formatPercent(Number n, String locale, int decimalPlaces)

  • String formatDate(Date d, String pattern)

  • String formatDate(Date d, String pattern, String locale)

Table 7.4. Log

The Log object interfaces with the Log4J logging mechanism used throughout Elixir Report Designer.

  • void error(String msg)

  • void warn(String msg)

  • void info(String msg)

  • void debug(String msg)

Table 7.5. Properties

The Parameters object provides a helper function to access report parameters. If this function is called from within a subreport it will return the subreport value for the property, but if not found there will return the parent report value instead. To set the parameter value you need to choose which report should hold the value and use the setParameter method of that RawReport (which could be either a master or a subreport). Similarly you can get a parameter from a report directly (ignoring master-subreport inheritance) by using the RawReport function getParameterValue.

Properties is deprecated and is kept for backward compatibility.

  • String get(String name)

Table 7.6. Renderer

The Renderer object provides an interface to the render engine. There are two functions here, eval and exec for invoking the JavaScript engine. These are only needed if you construct JavaScript expressions within JavaScript itself, and want to run them. Use eval when you expect a return value, use exec when no return is needed.

  • Object eval(String src, String lang, String code)

    • src: The name of the code being evaluated - displayed in error messages
    • lang: The script language used - must be "javascript" at present
    • code: The code to be evaluated
    • return: The result of evaluating the script
  • void exec(String src, String lang, String code)

    • src: The name of the code being executed - displayed in error messages
    • lang: The script language used - must be "javascript" at present
    • code: The code to be executed
    • return: None
  • LogicalElement getLogicalElementByName()

  • LogicalReport getLogicalReport()

  • String getMimeType()

  • RawElement getRawElementByName()

  • RawReport getRawReport()

  • void pageBreak()

  • void pageBreak(boolean resetPageCount)

Data Objects

Table 7.7. Data

The Data object represents the master datasource during section rendering. There are also helper methods for performing operations on named datasources. A number of the operations here return Function objects. The Function can then be applied to the desired record scope. See the Function object described below for more details.

  • int getRecordIndex()

  • int getRecordCount()

  • Object getCount(String)

  • String getString(String fieldName)

  • Object getObject(String fieldName)

  • Function getAverage(String fieldName)

  • Function getMax(String fieldName)

  • Function getMin(String fieldName)

  • Function getStandardDeviation(String fieldName)

  • Function getSum(String fieldName)

  • Function getVariance(String fieldName)

  • Function getAverage(String ds,String fieldName)

  • Function getMax(String ds,String fieldName)

  • Function getMin(String ds,String fieldName)

  • Function getStandardDeviation(String ds,String fieldName)

  • Function getSum(String ds,String fieldName)

  • Function getVariance(String ds,String fieldName)

Table 7.8. DataCache

Each DataCache object holds a data table in memory along with an index to the current record in the table. A DataCache is created by the DataCacheManager or by filtering an existing DataCache.

  • void reset()

  • void reset(Properties props)

  • int getRecordCount()

  • int getRecordIndex()

  • boolean hasNext()

  • void next()

  • int getColumnCount()

  • String getColumnName(int index)

  • int getColumnIndex(String fieldname)

  • Object getObject(int rowIndex, String fieldname)

  • Object getObject(int rowIndex, int columnIndex)

  • void moveToRow(int rowIndex)

  • Object getObject(String fieldname)

  • String getString(String fieldname)

  • int seekTo(String fieldname, Object value)

  • DataCache filter(String fieldname, Object value)

Table 7.9. DataCacheManager

The DataCacheManager provides an interface to load or discard DataCaches from memory.

  • DataCache loadCache(String dsnname, Properties props)

  • DataCache loadCache(String dsnname, Object cacheName, Properties props)

  • boolean hasCache(Object cacheName)

  • DataCache getCache(Object cacheName)

  • void putCache(Object newCacheName, DataCache cache)

  • void removeCache(Object cacheName)

Table 7.10. Function

A Function is returned by the Data object to represent the different operations that can be performed on data - for example getSum(fieldName). Given the function, you can execute it by specifying the range of records you want to be included in the result. For example,

Data.getSum("Salary").getValueOverAll();
  • Object getValueOverAll()

  • Object getValueOverGroup()

  • Object getRunningValueOverAll()

  • Object getRunningValueOverGroup()

Table 7.11. GroupNode

A GroupNode represents a range of records - typically as a result of a grouping operation. GroupNodes form a tree structure with a single root which encompasses the whole datasource, which is then subdivided into child groups recursively, based on the section grouping configuration.

  • boolean hasChildren()

  • Iterator getChildIterator() // child GroupNodes

  • int getStart() // the first index in the group

  • int getStop() // the last index in the group

  • GroupNode getParent() // null if topmost group

Raw Report Objects

The current raw object is accessed as this in the renderIf, onRenderBegin, onRenderEnd and onLayout scriptlets.

See the RML-RawModel.pdf in /docs for full details of the raw objects.

Logical Report Objects

Logical Report objects are only accessible in onRenderEnd and onLayout. They are identified using the result variable. Most raw elements are converted to more than one logical element. For example, a raw Field is rendered as a logical Rectangle which contains one or more logical Text objects - one for each line of output. Accessing the Text within the result is illustrated (in the onRenderEnd example above) like this:

field = result.getLogicalElement(0);

Where field is the first line of text in the result rectangle. You can query the number of child elements with:

count = result.getLogicalElementCount();

Wherever possible work with the raw objects, rather than the logical ones, as the dealing with logical objects requires an intimate knowledge of the rendering process and logical objects are more likely to change as new features are added.

See RML-LogicalModel.pdf in /docs for full details of the logical objects.