Introduction

Creating reports and dashboards is not only about visualizing data but also about processing and analyzing complex expressions using data columns and functions. For instance, expressions often appear in multiple places, and any required changes necessitate editing these expressions across various locations. This increases the risk of errors and the time spent on edits.

User functions help reduce the risk of errors by encapsulating expressions into a single reusable module. Instead of copying complex expressions, you can simply call the function wherever needed.

How does it work?

Functions are created in the report's data dictionary. They can be configured with descriptions, categories, return values, and arguments. Functions can be defined using either the Blockly visual programming tool or one of the following programming languages: JS, C#, or VB.NET:

  • Blockly: A visual programming tool that requires no code writing.

  • Scripting languages: Programming languages such as JS, C#, or VB.NET used within the report.


Advantages of user functions

1. Ease of script creation with zero code

  • The Blockly visual interface enables script creation without writing any code.

  • The versatility of Blockly scripts ensures compatibility of functions across all Stimulsoft platforms.

2. Reusability

  • A function created once can be used in multiple parts of the report, saving time and reducing errors.

3. Ease of expression updates

  • Any changes are made only in the function description, automatically updating expression calculations wherever the function is used.


Here are some important considerations when creating user functions:

  • Calculation Mode: In .NET and .NET Framework, functions are available only in compile mode. More details on this can be found in this article. For .NET and .NET Framework, you can select C# or VB.NET as the scripting language to define the function. For other platforms (JS, PHP, Python), access to events that execute the function description is crucial.

  • Access settings: Ensure that compilation or interpretation settings are enabled; otherwise, the functions will not work.

  • Script language choice: Functions operate in the language specified in the report’s properties (e.g., JS, C#, VB.NET).




Function configuration

Functions are configured in the editor, which provides detailed options. To start, open the editor by selecting New Function in the New menu of the data dictionary and define its parameters.

New user function

  • Name: All calls to the function are made using its name, which can be specified in this field.

  • Description: Allows you to add additional information about the function, displayed in the description panel of the data dictionary.

  • Function Category: Enables you to define which category in the data dictionary the function will be added to. You can select one of the predefined categories or set it to Custom. If Custom is selected, a field will appear for creating a custom category.

  • Custom Category: If the Custom option is selected, you can specify the name of a new category. If the field is left empty, the function will be placed in the root Functions category.

  • Return Type: Specifies the data type that the function returns.

  • Adding function arguments: Using the Add button, you can add up to 10 arguments. For each argument, you can configure:

    1. Argument Type: Specifies the data type of the argument.

    2. Argument Name: The name of the argument, used to reference it in the code.

  • Script Mode: Provides two options for implementation:

    1. Blocks: Uses the visual Blockly constructor, universal for all Stimulsoft platforms.

    2. Code: Allows you to write the function using a scripting language supported by the report (JS, C#, VB.NET).


Conclusion

User functions it’s a feature which helps the reuse of complex expressions, reduce development time, and minimize errors. Creating function scripts with Blockly makes the process accessible and simple while ensuring compatibility across all Stimulsoft platforms. We recommend using user functions to speed up report and dashboard creation, improve calculation accuracy, and make documents easier to modify.
By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.