Previous Next

Class BirtComp

The BirtComp class provides functions to compare values, for example, to test if a value is equal to, greater than, or less than another value. All the functions return either true or false. This class is static. The application cannot create instances of the class.

BirtComp.anyOf

This function tests if a value or values is found in a field.

Syntax

BirtComp.anyOf( source, target1, ..., targetN )

Parameters

source

The field that contains the values to compare to.

target

The value or values to find in source.

Returns

True if a target value matches a value in source; returns false otherwise.

Examples

The following example tests if Canada, Mexico, or USA are values in the Country field. If any one of the countries is in the field, the function returns true.

BirtComp.anyOf( row["Country"], "Canada", "Mexico", "USA" )

The following example tests if Jan 15, 2009 or Jan 31, 2009 are values in the payDate field:

BirtComp.anyOf( row["payDate"], "2009-01-15", "2009-01-31" )

The following example tests if two specific product codes are values in the productCode field. If either value appears in the field, the string Obsolete is displayed; otherwise the productCode value is displayed as it appears in the field.

if (BirtComp.anyOf(row["productCode"], "S18_1749", "S18_2248" )){
  displayString = "Obsolete"
  }
else{
  row["productCode"]
  }

BirtComp.between

This function tests if a value is between two specified values.

Syntax

BirtComp.between( source, target1, target2 )

Parameters

source

The value to test.

target1

The first value in the range of values to compare to.

target2

The second value in the range of values to compare to.

Returns

True if the source value is between the target1 and target values; returns false otherwise.

Examples

The following expressions test field values to see if they are within a specified range of values:

BirtComp.between( row["SalesTotal"], 10000, 20000 )
BirtComp.between( row["CustomerName"], "A", "M" )
BirtComp.between( row["OrderDate"], "2009-01-01", "2009-01-31" )

The following example calculates shipment dates. If an OrderDate value is in December 2008 (between 12/01/08 and 12/31/08), add 5 days to the OrderDate value. If an OrderDate value is in a month other than December, add 3 days to the OrderDate value.

if (BirtComp.between(row["OrderDate"], "2008-12-01", "2008-12-31" )){
  shipDate = BirtDateTime.addDay( row["OrderDate"], 5 )
  }
else{
  ShipDate = BirtDateTime.addDay( row["OrderDate"], 3 )
  }

BirtComp.compareString

This function tests if a string value matches another string value, given specified conditions.

Syntax

BirtComp.compareString( source1, source2, ignoreCase, trim )

Parameters

source1

The first string value to use in the comparison.

source2

The second string value to use in the comparison.

ignoreCase

Specify true to perform a case-insensitive comparison. Specify false to perform a case-sensitive comparison.

trim

Specify true to remove any leading or trailing blanks before comparing the two values. Blanks in the middle of a string are not removed. Specify false if you want the comparison to include leading or trailing blanks.

Returns

True if the source1 value matches the source2 value; returns false otherwise.

Examples

The following expressions compare strings with different conditions specified:

BirtComp.compareString( "Jackson", "Jackson", false, false ) // returns true
BirtComp.compareString( "Jackson", "jackson", false, true ) // returns false
BirtComp.compareString( "Jackson", "jackson", true, false ) // returns true
BirtComp.compareString( "Jackson ", "jackson", true, false ) // returns false
BirtComp.compareString( "Jackson ", "jackson", true, true ) // returns true

BirtComp.equalTo

This function tests if a value is equal to another value.

Syntax

BirtComp.equalTo( source, target )

Parameters

source

The first value to use in the comparison.

target

The second value to use in the comparison.

Returns

True if the source value is equal to the target value; returns false otherwise.

Examples

The following expressions test field values to see if they are equal to specified values:

BirtComp.equalTo( row["SalesTotal"], 10000 )
BirtComp.equalTo( row["Country"], "France" )
BirtComp.equalTo( row["OrderDate"], "2009-02-15" )

BirtComp.greaterOrEqual

This function tests if a value is greater than or equal to another value.

Syntax

BirtComp.greaterOrEqual( source, target )

Parameters

source

The first value to use in the comparison.

target

The second value to use in the comparison.

Returns

True if the source value is greater than or equal to the target value; returns false otherwise.

Examples

The following expressions test field values to see if they are greater than or equal to specified values:

BirtComp.greaterOrEqual( row["SalesTotal"], 10000 )
BirtComp.greaterOrEqual( row["ProductCode"], "S50_4000" )
BirtComp.greaterOrEqual( row["OrderDate"], "2009-02-15" )

BirtComp.greaterThan

This function tests if a value is greater than another value.

Syntax

BirtComp.greaterThan( source, target )

Parameters

source

The first value to use in the comparison.

target

The second value to use in the comparison.

Returns

True if the source value is greater than the target value; returns false otherwise.

Examples

The following expressions test field values to see if they are greater than specified values:

BirtComp.greaterThan( row["SalesTotal"], 10000 )
BirtComp.greaterThan( row["CustomerName"], "M" )
BirtComp.greaterThan( row["OrderDate"], "2009-02-15" )

BirtComp.lessOrEqual

This function tests if a value is less than or equal to another value.

Syntax

BirtComp.lessOrEqual( source, target )

Parameters

source

The first value to use in the comparison.

target

The second value to use in the comparison.

Returns

True if the source value is less than or equal to the target value; returns false otherwise.

Examples

The following expressions test field values to see if they are less than or equal to specified values:

BirtComp.lessOrEqual( row["SalesTotal"], 10000 )
BirtComp.lessOrEqual( row["ProductCode"], "S18_4000" )
BirtComp.lessOrEqual( row["OrderDate"], "2009-02-15" )

BirtComp.lessThan

This function tests if a value is less than another value.

Syntax

BirtComp.lessThan( source, target )

Parameters

source

The first value to use in the comparison.

target

The second value to use in the comparison.

Returns

True if the source value is less than the target value; returns false otherwise.

Examples

The following expressions test field values to see if they are less than specified values:

BirtComp.lessThan( row["SalesTotal"], 10000 )
BirtComp.lessThan( row["CustomerName"], "M" )
BirtComp.lessThan( row["OrderDate"], "2009-02-15" )

BirtComp.like

This function tests if a string value matches a pattern. The pattern must use SQL pattern-matching syntax.

Syntax

BirtComp.like( source, target )

Parameters

source

The string value to evaluate.

target

The string pattern to match. You must enclose the pattern in double quotation marks (" "). Use the correct case when typing the characters that you want to match. You can use the following special character in a pattern:

n  
A percent character (%) matches zero or more characters. For example, %ace% matches any string value that contains the substring ace, such as Facebook and MySpace. It does not match Ace Corporation because this string contains a capital A, and not the lowercase a.
n  
An underscore character (_) that matches exactly one character. For example, t_n matches tan, ten, tin, and ton. It does not match teen or tn.

To match a literal percent (%) or underscore (_) character, precede those characters with two backslash (\\) characters. For example, to match S_10, use the following pattern:

S\\_10

To match 50%, use the following pattern:

50\\%

Returns

True if the source value matches the target value; returns false otherwise.

Examples

The following example returns true for values in the productCode field that start with S18:

BirtComp.like( row["productCode"], "S18%" )

The following example returns true for productName values that contain the substring Ford preceded by a single character:

BirtComp.like( row["productName"], "_Ford%" )

BirtComp.match

This function tests if a string value matches a pattern. The pattern must use JavaScript regular expression syntax.

Syntax

BirtComp.match( source, target )

Parameters

source

The string value to evaluate.

target

The string pattern to match. In JavaScript regular expression syntax, you specify a pattern within a pair of forward slash (/) characters. You can use any special character supported by JavaScript regular expressions, such as the following:

n  
A question mark (?) matches zero or one occurrence of the character previous to it. For example, /te?n/ matches tn, ten, and often. It does not match teen or intern.
n  
An asterisk (*) matches zero or any number of occurrences of the character previous to it. For example, /te*n/ matches tn, ten, often, and teen. It does not match intern.
n  
n  
A caret (^) specifies that the substring to look for is at the beginning of a string. For example, /^ten/ matches ten, tennis, and tense. It does not match often or pretend.
n  

To match a special character literally, precede the special character with a backslash (\) character. For example, to match S*10, use the following pattern:

/S\*10/

Returns

True if the source value matches the target value; returns false otherwise.

Examples

The following example returns true for values in the productCode field that start with S18:

BirtComp.match( row["productCode"], /^S18/ )

The following example returns true for productName values that contain the substring Ford:

BirtComp.match( row["productName"], /Ford/ )

BirtComp.notBetween

This function tests if a value is not between two specified values.

Syntax

BirtComp.notBetween( source, target1, target2 )

Parameters

source

The value to test.

target1

The first value in the range of values to compare to.

target2

The second value in the range of values to compare to.

Returns

True if the source value is not between the target1 and target values; returns false otherwise.

Examples

The following expressions test field values to see if they are outside a specified range of values:

BirtComp.notBetween( row["SalesTotal"], 10000, 20000 )
BirtComp.notBetween( row["CustomerName"], "A", "M" )
BirtComp.notBetween( row["OrderDate"], "2009-01-01", "2009-01-31" )

The following example calculates shipment dates. If an OrderDate value is not in December 2008 (not between 12/01/08 and 12/31/08), add 3 days to the OrderDate value. If an OrderDate value is in December, add 5days to the OrderDate value.

if (BirtComp.notBetween(row["OrderDate"], "2008-12-01", "2008-12-31" )){
  shipDate = BirtDateTime.addDay( row["OrderDate"], 3 )
  }
else{
  ShipDate = BirtDateTime.addDay( row["OrderDate"], 5 )
  }

BirtComp.notEqual

This function tests if a value is not equal to another value.

Syntax

BirtComp.notEqual( source, target )

Parameters

source

The first value to use in the comparison.

target

The second value to use in the comparison.

Returns

True if the source value is not equal to the target value; returns false otherwise.

Examples

The following expressions test field values to see if they are not equal to specified values:

BirtComp.notEqual( row["SalesTotal"], 10000 )
BirtComp.notEqual( row["Country"], "France" )
BirtComp.notEqual( row["OrderDate"], "2009-02-15" )

BirtComp.notLike

This function tests if a string value does not match a pattern. The pattern must use SQL pattern-matching syntax.

Syntax

BirtComp.notLike( source, target )

Parameters

source

The string value to evaluate.

target

The string pattern to compare to. You must enclose the pattern in double quotation marks (" "). Use the correct case when typing the characters that you want to match. You can use the following special character in a pattern:

n  
A percent character (%) matches zero or more characters. For example, %ace% matches any string value that contains the substring ace, such as Facebook and MySpace. It does not match Ace Corporation because this string contains a capital A, and not the lowercase a.
n  
An underscore character (_) that matches exactly one character. For example, t_n matches tan, ten, tin, and ton. It does not match teen or tn.

To match a literal percent (%) or underscore (_) character, precede those characters with two backslash (\\) characters. For example, to match S_10, use the following pattern:

S\\_10

To match 50%, use the following pattern:

50\\%

Returns

True if the source value does not match the target value; returns false otherwise.

Examples

The following example returns false for values in the productCode field that start with S18:

BirtComp.notLike( row["productCode"], "S18%" )

The following example returns false for productName values that contain the substring Ford preceded by a single character:

BirtComp.notLike( row["productName"], "_Ford%" )

(c) Copyright Actuate Corporation 2011