Creating functions

You create a function to define reusable logic that accepts input parameters and returns a calculated output value.

Procedure

  1. Click the Add button Add data type button next to Data model and select Function from the drop-down list.
  2. Replace the default function name with a descriptive name. It is recommended to use a singular form for the function name.
  3. Optional: Define a documentation property using the Documentation text field. This documentation is visible in the prediction menu in the rule editor.
  4. 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.
  5. Define the input parameters for the function:
    1. Click Add + in the Input parameters section.
    2. Enter a suitable name for the parameter. It is recommended to use a singular form for the parameter name.
    3. Associate the parameter with a data type that you select from the Type drop-down list.
    4. Optional: Identify the parameter as a list by checking List. When a parameter is identified as a list, it can have multiple values.
    5. Optional: Edit the default verbalization of the parameter.
    6. Repeat for other parameters.
  6. 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.
  7. Define the body of the function:
    1. 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.
    2. 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.