Writing a Custom Expression

You can write your own custom expressions to control how Conditional Router routes records using the Groovy scripting language to create an expression.

Using Groovy Scripting

For information about Groovy, see groovy-lang.org.

Groovy expressions used in the Conditional Router stage must evaluate to a Boolean value (true or false) which indicates whether the record should be written to the port. The record is routed to the first output port whose expression evaluates to true.

For example, if you need to route records with a validation confidence level of >=85 to one stage and records with a validation confidence level of <85 to another stage, your script would look like:

data['Confidence']>=85

The script for the other port would look like:

data['Confidence']<85

The router would evaluate the value of the Confidence field against your criteria to determine which output port to send it to.

Checking a Field for a Single Value

This example evaluates to true if the Status field has 'F' in it. This would have to be an exact match, so 'f' would not evaluate to true.

return data['Status'] == 'F'; 

Checking a Field for Multiple Values

This example evaluates to true if the Status field has 'F' or 'f' in it.

boolean returnValue = false;
if (data['Status'] == 'F' || data['Status'] == 'f')
{
 returnValue = true;
}
return returnValue; 

Evaluating Field Length

This example evaluates to true if the PostalCode field has more than 5 characters.

return data['PostalCode'].length() > 5; 

Checking for a Character Within a Field Value

This example evaluates to true if the PostalCode field has a dash in it.

boolean returnValue = false; 
if (data['PostalCode'].indexOf('-') != -1) 
{ 
	returnValue = true; 
} 
return returnValue; 

Scripting Guidelines

  1. Column names must be enclosed within either single or double quotes.

    For example, this syntax is incorrect because rhe column name PostalCode is not enclosed within either single or double quotes.

    return data[PostalCode];
  2. A column name must be specified.

    For example, this syntax is incorrect because no column is specified.

    return data[]; 
  3. A return statement must return a boolean value.

    For example, this script is incorrect because row.set('PostalCode', '88989') does not return a boolean value. It just sets the value of the PostalCode field to 88989.

    return row.set('PostalCode', '88989');
  4. Use a single equals sign (=) to set the value of a field, and a double equals sign (==) to check the value of a field.