Overview of Custom Functions

Custom functions provide the ability to define rule functions specific to a project and use these in rule documents. This allows logic to be shared across rules where the same calculation is needed, for example, where an author would like to re-use rules by varying only a few input values (that is, just attribute values) in multiple places within their project. Custom functions can access data outside of their scope, which allows them to access complex entity structures when necessary. They can also be shared across projects by placing them inside an inclusion, and an inclusion could contain any number of custom functions, allowing a library of functions to be created.

Custom functions are implemented as special kind of entity with some additional properties attached:

  • A name which is used in rules to invoke the function.

  • An ordered list of arguments. Each argument consists of a name and an attribute and can be any of the basic attribute data types (that is, Boolean, text, number, currency, date, datetime or time).

  • A "return" attribute, which can also be one of the basic attribute data types.

At runtime, each invocation of the custom function creates an instance of the custom function entity, setting the argument attributes to the values that were passed into the custom function. It then evaluates all the rules associated with that entity, and finally returns the value of the return attribute to the expression that originally called the custom function.

In most respects, custom function entities act like any other kind of (inferred) entity. Attributes and relationships can be associated with the entity just like any other entity (with some limitations detailed in the related topics below). Almost any supported Policy Modeling rule capability can be used inside a custom function.