Create a Custom Function

Custom functions are managed on the Data tab in Policy Modeling.

To create a custom function:

  1. On the Data tab, click the New Custom Function button.

    The New Custom Function button on the Data tab in Policy Modeling

  2. In the Custom Function dialog, specify the following details:

    • Function Name - the name used to call the function from a rule. It cannot have the same name as a built-in function. It must start with a letter, and afterwards only letters, numbers, or '-' are allowed, and it must be unique within the project. For example, EndOfTaxYear.

    • Entity Text - the entity text. By default, this is ‘the <function name> function’ (the exact text is language-dependent). For example, the EndOfTaxYear function.

    • Argument Name - the name used as the placeholder for that argument when using the Rule Assistant to insert the function into a rule. By default, this is argument 1. Argument names do not need to be unique but must conform to normal attribute text conventions. Note that:

      • Additional arguments can be added by clicking the Add button. By default, these will be named argument 2, argument 3 and so on for any additional arguments added.

      • Arguments can be re-ordered using the menu button The menu button in the Custom Function dialog in Policy Modeling.

    • Attribute Text - the text of the attribute that will receive the value of the function argument when the function instance is created. By default, this is ‘<entity text><argument name>’. For example, the EndOfYear function argument 1.

    • Type - this is both the attribute type for the argument's attribute, as well as the attribute type that must be passed in when the function is called. The type cannot be "auto", it must be a concrete type (that is, Boolean, Number, Currency, Text, Date, Date and time, Time of day).

    • Return Value - the text of the attribute that the author is expected to infer to the function's result. By default, this is ‘<entity text> result’. For example, the EndOfTaxYear function result. The type of the return value also needs to be specified (that is, Boolean, Number, Currency, Text, Date, Date and time, Time of day).

    The Custom Function dialog in Policy Modeling showing an EndOfTaxYear custom function defined

  3. Click OK. The custom function is created in a folder called Custom Functions that sits adjacent to the Global entity. It is named <entity text><function name>. For example, the EndOfTaxYear function/EndOfTaxYear. A warning is displayed on the Rules tab until a rule inferring the return value has been written. For more information, see Write Rules Using Custom Functions.

The warning in Policy Modeling shown when a custom function is created but a rule setting the return value is yet to be written

Notes on naming and renaming custom functions

A custom function is not generally allowed to have the same name as a built-in function, but it is possible that a new built-in function could be added to a future version of the product that clashes with a custom function a user has defined. In this case, the custom function will take precedence over the built-in function. That is, a rule that calls the function by name will always invoke the custom function. The user will not be able to edit the custom function without changing the name, however.

In the Custom Function dialog, if the entity text is renamed, attributes containing that entity will also be renamed. This process mirrors what already happens in the entity editor. For more information, see Change Entity Text. Similarly, changing the text of an argument attribute in the dialog will rename the existing attribute, and if this conflicts with an existing attribute, then an error occurs.