Functions
This page describes DecisionRules Functions which are extremely useful for building decision processes of any complexity.
Last updated
This page describes DecisionRules Functions which are extremely useful for building decision processes of any complexity.
Last updated
Functions can be used in Decision Tables and Decision Trees to write mathematical and other functional expressions, both in the conditions and results. On this introductory page, you can make yourself familiar with the basic principals of writing functions in DecisionRules. The detailed documentation of all the available functions is provided on the subsequent pages.
We are constantly maintaining and improving our functions to provide the best user experience while keeping all changes backwards compatible. Functions are divided into several categories with respect to the area of their application. The categories are the following:
Math functions
Logical functions
Date and time functions
Text functions
Data functions
Array functions
Integration functions
DecisionRules Functions have a wide range of applications and behavior, however, there are some basic principals that apply universally. Let us give a brief exposition of these principals supported by basic practical examples. For more examples and information about the behavior of the individual functions, see their respective documentation.
The functions syntax is quite simple. Functions are denoted by their names (always uppercase, sometimes including underscores) and brackets that enclose individual function arguments separated by comma.
Each function can take different number of arguments, some of which may be optional. There are even functions that do not need any argument at all.
DecisionRules supports several distinct data types. There are primitive values: number, string, boolean, and null. There are also complex types like arrays and objects. Within functions, we support several additional types like date or regular expression. More information on data types within DecisionRules can be found on the Supported Data Types page. Here, let us only recall the basic syntax.
As you can see above, strings are standardly entered in double quotes. In case of simple string expressions that do not contain special characters [*/+-(),%{}], it is possible to omit the quotes. Nevertheless, we recommend to keep them for clarity and consistency.
If you need to use the double quotes character as part of a string, you can alternatively employ single quotes to define the string. Functions also support basic escaping of double quotes, simple quotes and backslashes:
Functions are usually defined in such a way that they cast the given value to the correct type themselves wherever it is possible, so that the user does not have to pay attention to the types. Let us take once again the example of the familiar function SUM which returns the sum of its arguments. By nature, SUM should of course take numbers as arguments.
Nevertheless, when given numerical values as strings, it treats them correctly, too.
Of course, it is not always possible to cast values to the required type. If this happens, the expression will either not pass validation or fail during execution. Most errors in this regard can be avoided by simply using functions in accordance with the documentation.
Some functions allow or even require complex data types: arrays and objects. In fact, the former holds for SUM which accepts arrays as arguments. Below you can see SUM given a single argument, which is an array of numbers. It sums up the numbers inside the array and returns the correct result.
DecisionRules uses JSON syntax for arrays and objects. It is easy to understand and work with. See a couple of basic examples below.
Functions can be nested inside each other.
Here, the MAX function returns the maximum of its elements, which is 2, and this result is then passed to the SUM function, which adds it up with 1 and returns 3.
DecisionRules Functions have special syntax for variables. There are four kinds of variables that may enter in functions. Let us briefly describe each of them.
Input variables. These represent the rule input data, as defined by the Input model.
Output variables. These represent the rule output data, as defined by the Output model.
Rule variables. These are user defined values with the scope of the rule. See more here.
Abstract function variables. These are special variables used in certain functions.
The particular kind and usage of the variable is not important for now since they are all used in the same way. Just write the name of the variable in curly brackets, anywhere you want to use it. The value saved in the variable will be picked up by the rule solver and used to evaluate the expression.
Of course, it may happen that the value coming from the variable cannot be used. Then, the evaluation will simply fail and return an empty value.
Decision tables have two types of columns, condition columns and result columns. Both can use functions but there is one basic distinction. While the cells in result columns can use functions without any limitations (because you may put anything in your results), the cells in condition columns may, by their nature, only contain functions that evaluate to boolean values, that is, their result has to be true or false. Therefore, functions in condition cells of a decision table usually employ some Logical function that wraps the rest of the expression.
When using functions in a decision table, you can turn on the Debug Mode and open the Console to see the detail of how they evaluated.