- Getting Started
-
Administration Guide
- Get Started with Administering Wyn Enterprise
- Configuration Settings
- Account Management
- Security Management
- System Management
- Document Management
- How To and Troubleshooting
- User Guide
- Developer Guide
User Functions
Wyn Enterprise has a variety of functions to perform date-time, mathematical, comparison, aggregation, text, and other operations. If these functions are not sufficient, a user can add new functions to Expression Editor with syntax, description, and example, like the built-in functions.
See the example below that uses a user-defined function, CountChar, to count the occurrences of a specified character in a string.
Following is the code for the CountChar function defined in CSharp and Visual Basic.
/// <function name="CountChar">
/// <culture>
/// <label>CountCharacter</label>
/// <syntax>CountChar(<str>, <char>)</syntax>
/// <description>Returns the number of occurrences of the specified character in the string.</description>
/// <example>Code.CountChar("Wyn Enterprise", "e")</example>
/// </culture>
/// </function>
public int CountChar(string str, string ch)
{
return str.Length - str.Replace(ch, "").Length;
}
''' <function name="CountChar">
''' <culture>
''' <label>CountCharacter</label>
''' <syntax>CountChar(<str>, <char>)</syntax>
''' <description>Returns the number of occurrences of the specified character in the string.</description>
''' <example>Code.CountChar("Wyn Enterprise", "e")</example>
''' </culture>
''' </function>
Public Function CountChar(str As String, ch As String) As Integer
Return str.Length - str.Replace(ch, "").Length
End Function
These functions are added and managed by the admin user role on the User Functions page of the Admin Portal.
Writing the Function Code
A function code consists of XML descriptions and function definition, as illustrated below. The XML descriptions describe the name, culture, label, syntax, description, and example for the user function, which if specified correctly are passed to the Expression Editor and displayed in the Info section. The function definition provides the return type, body, and argument list for the user function.
/// <function name="MyFunction">
/// <culture>
/// <label>MyFunction</label>
/// <syntax>MyFunction(<ArgumentName>)</syntax>
/// <description>Function description</description>
/// <example>Code.MyFunction("someValue")</example>
/// </culture>
public string MyFunction(string argumentName)
{
return $"Hello world, {argumentName}";
}
To generate culture-specific information in the Expression Editor, you can use the XML description as shown below. The culture code refers to the language code, which is unique for each language package, and is stored in the manifest.txt file. For more information, please see Create Custom Language Packages.
Based on your language preference, the Expression Editor will use the desired function code.
/// <function name="MyFunction">
/// <culture code="en-US">
/// <label>MyFunction</label>
/// <syntax>MyFunction(<ArgumentName>)</syntax>
/// <description>Function description</description>
/// <example>Code.MyFunction("someValue")</example>
/// </culture>
///
/// <culture code="ru-ru">
/// <label>МояФункция</label>
/// <syntax>MyFunction(<ИмяАргумента>)</syntax>
/// <description>Описание функции</description>
/// <example>{Code.MyFunction("некоеЗначение")}</example>
/// </culture>
/// </function>
public string MyFunction(string argumentName)
{
return $"Hello world, {argumentName}";
}
Note:
1. Expression Editor list only those functions that have XML description with <function> tag and name attribute.
2. Use HTML codes for less than and greater than symbols to avoid any compilation error.
With Wyn Enterprise, you can add multiple user functions depending on your requirements. It also lets you create more than one function with the same name if they have different arguments. These functions are implemented in CSharp or Visual Basic.
Adding the User Function
Follow the below steps to add user functions in Wyn Enterprise.
On the Admin Portal, navigate to the Configuration > WynReports Settings > User Functions.
On this page, type the code for the user function in the space provided or upload a file containing the function.
Tip: Click Generate to produce a sample function code with XML descriptions.
Then, click Compile to see compilation errors if any, and then select Save.
Note: The Save button is enabled when the function code for the available language(s) is compiled explicitly with no compilation errors.
The user function is now listed under the User Functions node of the Expression Editor in the Report Designer.