You create a function to define reusable logic that accepts input parameters and returns
a calculated output value.
Procedure
- Click the Add button
next to
Data model and select Function from the drop-down
list.
- Replace the default function name with a descriptive name. It is recommended to use a
singular form for the function name.
- Optional: Define a documentation property using the
Documentation text field. This documentation is visible in the prediction
menu in the rule editor.
- Under Output parameter, set the output type of the
function.
The output type can either be a built-in or custom data type. For more
information about supported data types, see
Data types.
- Define the input parameters for the function:
- Click Add + in the Input parameters
section.
- Enter a suitable name for the parameter. It is recommended to use a singular form for
the parameter name.
- Associate the parameter with a data type that you select from the
Type drop-down list.
- Optional: Identify the parameter as a list by checking
List. When a parameter is identified as a list, it can have multiple
values.
- Optional: Edit the default verbalization of the parameter.
- Repeat for other parameters.
- Optional: Click the Verbalization placeholder to edit
the default verbalization of the function and edit it directly in the pop-up window that
opens.
The default verbalization is based on the name of the function. You can revert to
the default verbalization by clicking Reset.
- Define the body of the function:
- Select the type of function that you want to define:
- BFL expression for a simple expression that returns a value.
- BFL code block for complex logic that requires multiple statements.
- In the editor, write the function logic by using the Business
Function Language (BFL).
Example
- Example 1: code block to calculate a yearly repayment amount
-
declare 'monthly rate' being the yearly interest rate of loan / 12 ;
declare 'monthly payment' being 'monthly rate' * the amount of loan / ( 1 - pow( 1 + 'monthly rate' , - the duration of loan ) ) ;
set result to 'monthly payment' * 12 ;
This yearly repayment function takes a loan as input and returns a
number.
- Example 2: simple expression to compute the age of a customer
-
the number of years between the birthday of 'the customer' and 'now'
This function calculates the age of a customer by using a customer ('the
customer') and a date and time ('now') as input parameters.