New to Telerik Reporting? Download free 30-day trial

Custom User Functions Overview

User functions allow you to extend the default behavior of the Telerik Reporting engine. User functions are public static (Public Shared in VB.NET) methods that should always return a value and can take an arbitrary number of input parameters.

Optional parameters are not supported. The Reporting engine uses reflection to discover and invoke the custom user functions. This requires an exact match between the number and the type of the function parameters.

There are two ways to utilize user functions:

  1. When any public static (Public Shared in VB.NET) method is part of the current report class. In this case, they can be invoked from an expression by their name, specifying the necessary parameters in the braces:

    Invoking a User Function from the same report class

    = ResolveUrl("~/Images/Logo.jpg")

  2. When any public static (Public Shared in VB.NET) method reside in a loaded assembly. In this case, they can be invoked from an expression by their fully qualified name, including the full namespace and the name of the type they belong to, and specifying the necessary parameters in the braces:

    Invoking a User Function from loaded assembly

    = Telerik.Reporting.Report.Report1.ResolveUrl("~/Images/Logo.jpg")

If the loaded assembly contains many public static (Public Shared in VB.NET) methods, this might produce some clutter in the Edit Expression dialog, when browsing for existing user functions. To overcome this problem, you can use the IsVisible attribute to hide any methods, which are not intended to be used as user functions. See the code sample below:

Example:

public class Report1 : Telerik.Reporting.Report
{
    //...
    [Function(IsVisible = false)]
    public static System.Drawing.Image ResolveUrl(string relativeUrl)
    {
        string path = System.Web.HttpContext.Current.Server.MapPath(relativeUrl);
        return System.Drawing.Image.FromFile(path);
    }
    //...
}

User Functions Visibility in Report Designers

As of 2025 Q1 (19.0.25.211), the User Function resolution behavior has been changed. The IsVisible property of the Function attribute can now be used to more precisely control which functions are loaded by the Reporting Engine. Below you can find more information about the new behavior:

  • By default, all public static methods in the chosen assembly(ies) are loaded;
  • If at least one public static method in the assembly(ies) is decorated with the Function attribute and has its IsVisible property set to True (true by default), only public static methods with the same configuration will be loaded. Public static methods that are not decorated with the Function attribute or have their IsVisible properties set to False, will not be loaded.
  • If a type is decorated with the Function attribute and has its IsVisible property set to False, none of the methods in this class will be loaded.
  • If a type is decorated with the Function attribute and has its IsVisible property set to True, all methods in it, except for the ones decorated with IsVisible = False, will be loaded.

Providing metadata for functions

You can provide descriptive metadata about your user functions through attributes. Attributes are specialized classes that are applied to code elements. At compile time, attributes are emitted into metadata that is available to the common language runtime and reporting engine.

Attributes are attached to a component by preceding the component with a reference to the attribute and providing any relevant parameters. This call to the constructor is placed within angle brackets <> in Visual Basic and regular brackets [] in C#.

FunctionAttribute

The FunctionAttribute allows you to specify metadata for user functions. This metadata describes the Category, Name, Namespace, Description, and whether this function should be visible (IsVisible) for the Reporting Engine or not. If it is visible, it will be displayed in the Edit Expression Dialog so you can utilize it in an Expression.

DescriptionAttribute

The DescriptionAttribute allows you to specify a description for the user function parameters. The description will be displayed in the Edit Expression Dialog when you select a User Function.

Example:

public static class MyUserFunctions
{
    [Function(Category = "My Functions", Namespace = "My", Description = "Say Hi")]
    public static string Greet(string name)
    {
        return string.Format("Hello, {0}", name);
    }
}

To invoke this function, set the following expression:

= My.Greet("John Doe")

Extending Reporting Engine with User Functions

If your custom user functions are linked from an external assembly, for the designer to recognize them, you will have to extend the configuration of the start application.

For the Visual Studio Report Designer this is the 'devenv.exe.config' file that resides in 'C:\Program Files (x86)\Microsoft Visual Studio X.0\Common7\IDE' by default (it is recommended to create a backup copy before modifying it). You can type the expression by specifying the full assembly qualified name of the function and passing a parameter of the expected type.

To run the report in other projects, use the same approach - add the assembly to the root folder from where the application is executed and configure it to load the external assembly by extending the configuration.