Others

Besides the above mentioned function types, JReport has some other functions as listed below:

Choose(Integer, Array)

Returns a value from the array based on the value of Integer. For example, if integer is 0, it returns the first element in the array, and if index is 1 it returns the second element in the array.

Parameters

Return value

A value from the element in the given array. The type of the returned value is the same as the type of the element.

Examples

currentBurstingSchema()

Returns the names of the applied bursting schemas in the current report. When isRunBursting() returns false, the returned value of currentBurstingSchema() is NULL.

Note: Formulas referring to currentBurstingSchema() are not allowed to be used in queries or datasets.

Return value

The return value is a String.

Example

If the current report has been applied two bursting schemas: VP and Manager, the return value of the following statement is VP,Manager:

currentBurstingSchema()

eqv(booleanx, booleany)

Returns a Boolean value of booleanx eqv booleany,

Parameters

Return value

Boolean value.

Examples

getLanguage()

Returns the language name of the locale that the current running task is based on.

Return value

The return value will either be the empty string or a lowercase ISO 639 code.

Example

When the locale is set to en_US, the return value of the following statement is en:

getLanguage()

getSecurityContext()

Returns a security context object, which provides the method get() to get the Security Context instance from JReport Server or JReport Designer.

Return value

The return value is a DbSecurityContext object.

Example

Import userClass from "UserFunction";
userClass.getData(getSecurityContext(), @country, …);

isAll(Array)

Checks whether the value of the specified parameter is "ALL".

Return value

The return value is true or false.

Example

When the parameter PEndDate supports multiple values and its value is set to "All", the following statement returns true.

isAll(@PEndDate)

isCountry(String)

Compares the input parameter with that of the country setting of JVM based on default locale.

Parameter

The input string must be an uppercase 2-letter ISO 3166 code.

Return value

The return value is true or false.

Examples

IsNoRecord()

This function tells whether a report has returned a record or not. If the report has no value returned, the function will return True, otherwise False.

Note: A formula which calls this function cannot be applied to queries, and this formula only takes effect when laying out this report which contains it.

Example

When using this function, you should refer to a DBField to identify whether this formula is a record level formula so that it can be calculated when fetching the record. For example,

@"Customers_Customer ID";
if(IsNoRecord())
  return "There is no data"
else
  return "Total number of records="+@"Count_Customer Name5"

In this example, if no data returned, a tip "There is no data" will be displayed. If data is returned, the Total number of records will be displayed.

IsNull(DBfield a)

This function tells whether a specified value (especially the value of a DBField) is null or not. If the value is Null, the function will return True, otherwise False.

Parameter

a - A specified value especially a value of a DBField.

Return value

The return value is True or False.

Examples

isNumeric(inString)

Returns a Boolean value if the inString is a math number string.

Parameter

inString - A String type value.

Return value

Boolean value.

Examples

isRunBursting()

Returns true if the current report is running based on a bursting schema, else returns false.

Note: Formulas referring to isRunBursting() are not allowed to be used in queries or datasets.

Return value

The return value is true or false.

Examples

Next()

Next(DBfield a)

This function returns the next value of the current DBField.

Parameter

a - A DBField value.

Return value

The return value is a DBField value.

Example

Suppose you build a report about customer orders. If you use this function on "Ship Date" and insert it into the Detail Section, then when you run the report, you will see after each record, the next records will be displayed according to the following statement.

Next(@"Ship Date")

Next(DBfield a, BigInt b)

This function returns the next Nth record decided by the argument b.

Parameters

Return value

The return value is a DBField value.

Example

Suppose you build a report about customer orders. If you use this function on "Ship Date" and set the argument b as 1, then when you run the report, you will see after each record, the next first record will be displayed according to the following statement.

Next(@"Ship Date", 1)

Note: Due to some implementation limitation, the argument b cannot be equal to or larger than 2.

openBinFile(string a)

This function is used to open an image file which is saved in your file system according to the path specified by the parameter.

Parameter

a - A String value which indicates the full path of the image file.

Return value

The return value is a binary image file.

Example

Suppose you have an image file photo1.gif which is saved in the following directory c:\images. The following example will open this image file.

openBinFile("c:\\images\\photo1.gif")

openBinURL(string a)

This function is used to open a binary image file according to the URL which is specified by the parameter.

Parameter

a - A String value which indicates the URL of the image file.

Return value

The return value is a binary image file.

Example

Suppose you have an image file in the following URL http://www.jinfonet.com/../../asset/images/Pic1.gif. The following example will open this image file Pic1.gif.

openBinURL("http://www.jinfonet.com/../../asset/images/Pic1.gif")

openTxtFile(string a)

This function is used to open a text file which is kept in your file system according to the path specified by the parameter.

Parameter

a - A String value which indicates the full path of the text file.

Return value

The return value is a long varchar.

Example

Suppose you have a text file report.int in the following directory C:\JReport\Designer. The following example will open this text file report.ini.

openTxtFile("C:\\JReport\\Designer\\report.ini")

openTxtURL(string a)

This function is used to open a text file according to the URL specified by the parameter.

Parameter

a - A String value which indicates the URL of the text file.

Return value

The return value is a long varchar.

Example

Suppose you have a text file at the following URL http://www.jinfonet.com/JReport/report.ini. The following example will open the text file report.ini.

openTxtURL("http://www.jinfonet.com/JReport/report.ini")

Prev()

Prev(DBfield a)

This function returns the previous value of the current DBField.

Parameter

a - A DBField value.

Return value

The return value is a DBField value.

Example

Suppose you build a report about customer orders. If you use this function on "Ship Date" and insert it into the Detail Section, after the report has been run, you will see the previous records displayed after each record, according to the following statement.

Prev(@"Ship Date")

Prev(DBfield a, BigInt b)

This function returns the previous Nth record decided by the argument b.

Parameters

Return value

The return value is a DBField value.

Example

Suppose you build a report about customer orders. If you use this function on "Ship Date" and set the argument b as 4, then when you run the report, you will see before each record, the previous 4th record displayed according to the following statement.

Prev(@"Ship Date", 4)

Note: Due to some implementation limitation, the argument b cannot be equal to or less than -2.

reportName()

This function returns the current report name.

Return value

The return value is a String.

Example

If the current report name is EmployeeInformation, the return value of the following statement is EmployeeInformation.

reportName()

Switch(Boolean[], Array)

The elements in the two parameters corresponding with each other. This function evaluates the elements in the first parameter from left to right, and returns element associated with the first element to evaluate to True. For example,

Switch([1, 2, 3], [a, b, c])

if 1 is true, Switch returns a. If 2 is true, Switch returns b. If 3 is true, Switch returns c.

Parameters

Return value

One of the elements of the parameter array. The type of the returned value is the same as the element in the array.

Example

Insert the following function into the Detail section of a report,

Switch([@"Customers_Customer ID"< 5, @"Customers_Customer ID" > 50,true],["small", "large", "medium"])

toBool(number or currency)

Returns True if the parameter is positive or negative but not 0, and returns False if the parameter is 0.

Parameter

Can be either a Number, Currency value, or expression.

Return value

Boolean value.

Example

toBool(@Discount) - Returns false if the discount is 0. Otherwise, returns true.

toNumber(Boolean)

Returns 1 if the parameter is True, and returns 0 if the parameter is False.

Parameter

True or false.

Return value

1 or 0.

Examples

xor(booleanx, booleany)

Returns a Boolean value of booleanx Exclusive OR booleany,

Parameters

Return value

Boolean value.

Examples