Rules Syntax

Basics

A rule can either be defined as a single line expression (Expression Syntax) or as a multi line script (Script Syntax).

The expressions and scripts are defined in C# (C# Language Reference).

Expression Syntax

The expression syntax is used for quickly defining simple validation rules.

  • Every expression must start with an equal sign (=).
  • An expression must return either true or false.

Examples:

=Data("Gender").IsNotEmpty

or

=Data("Gender").String == "M" || Data("Gender").String == "F"

Script Syntax

Use the script syntax when your intend is to build a more complex rule that better gets broken down into multiple lines of code.

  • The script must end with a return instruction that returns either true or false.
  • Each line of the script must be terminated by a semicolon (;) how it’s always done in C#.

Example:

var gender = Data("Gender").String;
var allowedValues = new List<string>() { "M", "F" };
return allowedValues.Contains(gender);

or

var age = DateTime.Today.Year - Data("BirthDate").DateTime.Year;
var actualVacationDays = (double)Data("VacationHours").Decimal / 8.5;

var availableVacationDays = 0;
if (age <= 25) {
  availableVacationDays = 25;
}
else {
  availableVacationDays = 20;
}

return actualVacationDays == availableVacationDays;

Functionallity

You can use most of the features of the .NET Framework 4.6 and the syntax-features of C# 6.0.

We added additional functions that makes it easier and more efficient to work with the probe data.

Data(“Column-Name”)

Using the Data(…) function, you can access the value of a column of the probes dataset directly by its name.

The Data(…) function is only available in the Rules Expression and not in the pre-execute script.

The value from the data-field must be converted to the respective data-type using one of the following ways.

After conversion, you can access all properties of the respective .NET datatype.
=Data("birthdate").DateTime.Year == 1970

  • Data("Column-Name").String
    Returns the columns value as a character string. The function returns a .NET object of the type System.String. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").Integer
    Returns the columns value as a 32 bit integer value. The function returns a .NET object of the type System.Int32. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").Long
    Returns the columns value as a 64 bit integer value. The function returns a .NET object of the type System.Int64. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").Short
    Returns the columns value as a 16 bit integer value. The function returns a .NET object of the type System.Int16. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").Decimal
    Returns the columns value as a decimal value. The function returns a .NET object of the type System.Decimal. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").Boolean
    Returns the columns value as a boolean value. The function returns a .NET object of the type System.Boolean. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").DateTime
    Returns the columns value as a DateTime value. The function returns a .NET object of the type System.DateTime. Therefore you can use all functions and properties defined on this type.
  • Data("Column-Name").Convert<TYPE>()
    Use this function to convert a column-value into any .NET type that implements the IConvertible interface. Replace the placeholder TYPE by the fullqualified name of the target type.

IsNull() / IsNotNull()

Data("Column-Name").IsNull
Returns true when the field doesn’t contain any value (=NULL). There is also a Data("Column-Name").IsNotNull function you can use to do the vice versa.

IsEmpty() / IsNotEmpty()

Data("Column-Name").IsEmpty
Returns true when the field doesn’t contain any value (=NULL) or when it contains an empty string (“”). There is also a Data("Column-Name").IsNotEmpty function you can use to do the vice versa.

IsNumeric() / IsNotNumeric()

Data("Column-Name").IsNumeric
Returns true when the field contains a numeric value. There is also a Data("Column-Name").IsNotNumeric function you can use to do the vice versa.

Querying Data or Meta data

Availability: since Release 2.8.0

see Querying Data or Metadata
consider using this in the Pre Execute script only as it may slow down the performance dramatically.

Snippets

Availability: since Release 2.8.0

see Snippets

Placeholders

Availability: since Release 2.8.0

see Placeholders

Parameters

Availability: since Release 2.8.0

see Parameters

Parameter lists

Availability: since Release 2.8.0

see Parameter Lists

Logging

Availability: since Release 2.8.0

see Logging

Table of Contents