Custom Functions in the dictionary
Custom Functions in the dictionary
I have a couple proprietary functions that I would like my customers to have access to within the designer. I know there is a way to reference external assemblies and .NET code from the report designer but is there a way for me to add a custom code fragment and register it as a function in the dictionary's function list so it is easily available to my customers?
Thanks,
John Hamilton
Hamilton & Company, LLC
John Hamilton
Hamilton & Company, LLC
Custom Functions in the dictionary
I figured it out! Here's a quick rundown for those needing a little reference.
All you gotta do is come up with a class with a bunch of static methods that correspond to the functions you want to display in the function list. Then you do this:
The last function call does all the magic. You give it a category name and function name, types for return and parameter types and labels. You also give it a "function type" which is the name of the static class that contains the function that corresponds to the function name (ex. POSitiveSoftware.Common).
I would consult the docs for some of this but I find that the product changes so quickly that the docs usually are quite outdated so I come to the forums to get my questions answered. I hope you guys don't mind. This one was easy for me to figure out as I have another piece of code which adds predefined variables to the dictionary.
Thanks again stimulsoft. You guys are always 10 steps ahead of me.
All you gotta do is come up with a class with a bunch of static methods that correspond to the functions you want to display in the function list. Then you do this:
Code: Select all
///////////
// Data
///////////
#region Data
string Category;
string[] ParamNames;
Type[] ParamTypes;
string[] ParamDescrips;
#endregion
///////////
// Code
///////////
#region Code
Category = "PRM Functions";
ParamNames = new string[2];
ParamTypes = new Type[2];
ParamDescrips = new string[2];
ParamNames[0] = "PRMDate";
ParamDescrips[0] = "Integer value representing a PRM Date to be converted";
ParamTypes[0] = typeof(int);
ParamNames[1] = "PRMTime";
ParamDescrips[1] = "Integer value representing a PRM Time to be converted.";
ParamTypes[1] = typeof(int);
StiFunctions.AddFunction(Category, "ToSQLDateTime", "ToSQLDateTime", "Converts from PRM Standard Date and Time to an SQL DateTime",
typeof(POSitiveSoftware.Common), typeof(DateTime), "Returns an SQL DateTime representing the PRM Date and Time provided.",
ParamTypes, ParamNames, ParamDescrips);
#endregion
I would consult the docs for some of this but I find that the product changes so quickly that the docs usually are quite outdated so I come to the forums to get my questions answered. I hope you guys don't mind. This one was easy for me to figure out as I have another piece of code which adds predefined variables to the dictionary.
Thanks again stimulsoft. You guys are always 10 steps ahead of me.
Thanks,
John Hamilton
Hamilton & Company, LLC
John Hamilton
Hamilton & Company, LLC
Custom Functions in the dictionary
Hello Johnham,
Also you can register xml file with custom functions:
Thank you.
Also you can register xml file with custom functions:
Code: Select all
StiFunctionsXmlParser.LoadFunctionsFromXml(typeof(StiReport).Assembly, "Stimulsoft.Report.Dictionary.FunctionsDate.xml");
- Attachments
-
- 119.FunctionsDate.xml
- (6.58 KiB) Downloaded 1259 times
Custom Functions in the dictionary
One more question.
I added my custom function using my code fragment above. This worked when I created a variable in the dictionary and had it simply run my function against some dummy values.
However, today I went into the datasource editor. I added a parameter to my datasource and then used the expression editor to browse for my function in the function library. I double clicked on it and filled in the details. It looked something like so:
When I tried to preview my test report, it gave me "c:\Users\jhamilton\AppData\Local\Temp\assdilax.0.cs(687,69) : error CS0103: The name 'ToPRMDate' does not exist in the current context"
To fix this I had to go in and edit the parameter again and fully qualify the function name. It looks like this:
This is a fine solution for me but when my customers go to use my custom functions from the function library I don't know how they will know the namespace and classname to add. It also concerns me that it worked fine as an expression in the variables but not in the datasource parameters.
Do I need to register my assembly/class somewhere or is this a problem that needs to be fixed?
I added my custom function using my code fragment above. This worked when I created a variable in the dictionary and had it simply run my function against some dummy values.
However, today I went into the datasource editor. I added a parameter to my datasource and then used the expression editor to browse for my function in the function library. I double clicked on it and filled in the details. It looked something like so:
Code: Select all
ToPRMDate(dtpStartDate.Value)
When I tried to preview my test report, it gave me "c:\Users\jhamilton\AppData\Local\Temp\assdilax.0.cs(687,69) : error CS0103: The name 'ToPRMDate' does not exist in the current context"
To fix this I had to go in and edit the parameter again and fully qualify the function name. It looks like this:
Code: Select all
POSitiveSoftware.Common.ToPRMDate(dtpEndDate.Value)
Do I need to register my assembly/class somewhere or is this a problem that needs to be fixed?
Thanks,
John Hamilton
Hamilton & Company, LLC
John Hamilton
Hamilton & Company, LLC
Custom Functions in the dictionary
Is there any way to make this work with functions that I have added to a report file? We have a standard report template that our customers use and there are several static functions added to this that they can call. using the load from xml or the code method I cannot add these to the function list. I can only add functions in other classes.Vital wrote:Hello Johnham,
Also you can register xml file with custom functions:
Thank you.Code: Select all
StiFunctionsXmlParser.LoadFunctionsFromXml(typeof(StiReport).Assembly, "Stimulsoft.Report.Dictionary.FunctionsDate.xml");
Custom Functions in the dictionary
Hello Hohnham,
Thank you.
Its a bug. We don't check parameter value for functions. Please check next build.johnham wrote:One more question.
I added my custom function using my code fragment above. This worked when I created a variable in the dictionary and had it simply run my function against some dummy values.
However, today I went into the datasource editor. I added a parameter to my datasource and then used the expression editor to browse for my function in the function library. I double clicked on it and filled in the details. It looked something like so:
Code: Select all
ToPRMDate(dtpStartDate.Value)
When I tried to preview my test report, it gave me "c:\Users\jhamilton\AppData\Local\Temp\assdilax.0.cs(687,69) : error CS0103: The name 'ToPRMDate' does not exist in the current context"
To fix this I had to go in and edit the parameter again and fully qualify the function name. It looks like this:
This is a fine solution for me but when my customers go to use my custom functions from the function library I don't know how they will know the namespace and classname to add. It also concerns me that it worked fine as an expression in the variables but not in the datasource parameters.Code: Select all
POSitiveSoftware.Common.ToPRMDate(dtpEndDate.Value)
Do I need to register my assembly/class somewhere or is this a problem that needs to be fixed?
Thank you.
Custom Functions in the dictionary
Hello,
Thank you.
You need provide assembly which contain report functions together with your reports. Also you can place code of your function directly in your report code.mace242 wrote:Is there any way to make this work with functions that I have added to a report file? We have a standard report template that our customers use and there are several static functions added to this that they can call. using the load from xml or the code method I cannot add these to the function list. I can only add functions in other classes.Vital wrote:Hello Johnham,
Also you can register xml file with custom functions:
Thank you.Code: Select all
StiFunctionsXmlParser.LoadFunctionsFromXml(typeof(StiReport).Assembly, "Stimulsoft.Report.Dictionary.FunctionsDate.xml");
Thank you.
-
- Posts: 1
- Joined: Sun Jan 17, 2010 11:03 pm
Custom Functions in the dictionary
does the methods in the custom function class have to be ' static'? then how about Unit Test?
Custom Functions in the dictionary
Hi
Yes, the method must be static, there is no other way for it to be registered.
Thank you.
Yes, the method must be static, there is no other way for it to be registered.
Thank you.