Using Custom Functions in Formulas

You can use your own custom functions in formulas in your application.  There are three types of custom functions you can add:

Local Extensions

For localized extensions, you can add functions at the page, table control or row control levels.  Specifically, the formula language exposes variables for page object as well as the table control, record control and row objects.  So you can call any function you want on these classes as well.

For example, on the ShowCategoriesTable.aspx displaying a Categories table page, you can define functions on the ShowCategoriesTable page class, on the CategoriesTableControl class, or on the CategoriesTableControlRow class as needed.

As an example, if you defined the following non-shared (VB.NET) or non-static (C#) functions:

On the Formula tab, these formulas can be used to access each of these functions respectively:

= Page.GetPageValue()

= CategoriesTableControl.GetTableValue()

= CategoriesTableControlRow.GetRowValue()

Each of these functions can return a constant, another value local to their respective objects, call a function in another class, call another shared function on another class, another DLL or any other function that is possible to implement in the application.

Note that these formulas are context sensitive.  The Row function can only be called from within a row because the CategoriesTableControlRow variable is only accessible from the row.  Similarly, the Table function can be called from within the row or when within the table area (e.g., filters or buttons area).  The Page function can be called from anywhere on the page.

Application-wide Extensions

The formula functions for an application are implemented in two source code files within the application’s source code.  New formula functions can be added to these files, or existing functions can be modified as desired.

The formula functions are split into two files because some functions cannot be used within the WHERE clause of a query.  For example, the SUM, RANK or ROWNUM functions are specific to the presentation layer since they operate on textbox, literal and label controls on the web page.  These functions can only be used in the Property Sheet and cannot be used in the WHERE clause of a query.  Most functions however are generic and can be used in either the Property Sheet or the WHERE clause of a query.

Importing .NET Framework Classes and Functions

Any shared or static functions from either the .NET Framework or your own classes can be used by importing their types in the FormulaUtils.vb or FormulaUtils.cs class and registering them via the Evaluator.Imports.AddType() function, e.g.:

Evaluator.Imports.AddType(GetType(Math), "Math")

Evaluator.Imports.AddType(GetType(DateTime), "DateTime")

Evaluator.Imports.AddType(GetType(Convert), "Convert")

Evaluator.Imports.AddType(GetType(String), "String")

The first argument is the type and the second argument is the prefix (or namespace) used to refer to the function.

See Also

Variables Available in Formulas

Formula Evaluation Order


Using Table and Record Control Functions in Formulas

Using .NET Framework Functions in Formulas

Using Custom Functions in Formulas

Formula Error Reporting