Besides the above mentioned function types, JReport has some other functions as listed below:
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
Choose(1,["Poor","Fair","Good","Excellent"])
- Returns Fair.Choose(2,["1 to 10","11 to 20", "21 to 30"])
- Returns 21 to 30.Choose(2,[1,2,3,4,5,6])
- Returns 3.Choose(2,[Todate('1998/5/4'),ToDate('1999/5/5'),ToDate('1996/5/6')])
- Returns 5/6/96.Returns the names of the applied bursting schemas in the current report. When isRunBursting() returns false, the returned value of currentBurstingSchema() is NULL.
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()
Returns a Boolean value of booleanx eqv booleany,
Parameters
Return value
Boolean value.
Examples
eqv(true, true)
- Returns true.eqv(true, false)
- Returns false.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()
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, …);
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)
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
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,
|
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.
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
IsNull(2.5)
IsNull(@shipped)
Integer Total=0;
if (!isnull(@grandTotal))
Total= Total+@grandTotal;
else
Total=Total+0;
This formula can summarize the Grand Total while ignoring the null value or no-record column.
Returns a Boolean value if the inString is a math number string.
Parameter
inString - A String type value.
Return value
Boolean value.
Examples
isNumeric("true")
- Returns false.isNumeric("false")
- Returns false.isNumeric("1234")
- Returns true.isNumeric("122 322323")
- Returns false.Returns true if the current report is running based on a bursting schema, else returns false.
Return value
The return value is true or false.
Examples
isRunBursting()
isRunBursting()
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")
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.
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")
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")
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")
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")
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")
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.
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()
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"])
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.
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
toNumber(True)
- Returns 1.toNumber(False)
- Returns 0. Returns a Boolean value of booleanx Exclusive OR booleany,
Parameters
Return value
Boolean value.
Examples
xor(true, true)
- Returns false.xor(true, false)
- Returns true.xor((@"Customer ID"<=20),(Remainder(@"Customer ID", 2) == 0));