This is a migrated thread and some comments may be shown as answers.

User Functions

3 Answers 268 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul Bacci
Top achievements
Rank 1
Paul Bacci asked on 23 Sep 2009, 08:16 PM
Is it possible to pass a Report.Parameter to a user function by way of an expression?  This expression doesn't work:

= MyReportsLibrary.MyReport.myUserFunction(Parameters.parameter1,Parameters.parameter2)
The expression is attached to the value of a text-box.
parameter1 and parameter2 are strings.

This is the user function:

 

public static string myUserFunction(string str1,string str2)

 

{

 

return str1 + "/" + str2;
}

 


This is what gets populated into the text-box:

An error has occured while processing TextBox 'textBox1':
The expression contains undefined function call myUserFunction().

3 Answers, 1 is accepted

Sort by
0
Paul Bacci
Top achievements
Rank 1
answered on 23 Sep 2009, 08:55 PM
I have resolved this.  My actual app had a 3rd parameter that was declared an integer but i was casting the value to int16 and the function was expecting int32.
0
Ed
Top achievements
Rank 1
answered on 29 Sep 2010, 05:05 PM
There is another problem that causes the "undefined function call" error. From clues given by Telerik in another post in this forum:

<cite>Posted on May 18, 2010 (permalink)
Hi Enigma,

Internally all of the data types are converted to the "biggest" numeric data types (long and double) to avoid any data/precision loss (common practice in scripting languages). In this line of thoughts the Sum aggregate returns Int64 (long) data type when we sum int values.  In order the expression engine to recognize your User Function you have to modify it to accept Int64 parameters as shown ...</cite>

So, if you are passing an Integer value, and the value is from a report parameter defined as an Integer, your user function must be defined with an Int64. The confusing thing is that it will work sometimes for constants and database fields, but fails when you pass a parameter value. Example:

The expression:

=GetStartDate(Parameters.PreviousDays.Value)

throws the error when the user function defined as:

    Public Shared Function GetStartDate(ByVal previousDays As Integer) As Date
       Return Today.AddDays(-previousDays)
    End Function

but works correctly when the user function defined as:

    Public Shared Function GetStartDate(ByVal previousDays As Int64) As Date
        Return Today.AddDays(-previousDays)
    End Function

This cost me three long nights to figure out. It is something important that should have been clearly mentioned in the documentation, but was omitted.
0
Steve
Telerik team
answered on 06 Oct 2010, 02:00 PM
Hello Ed,

Indeed we agree that this information should be present in the documentation and I've added it immediately. The updated docs will be live with the next site upload.

Your Telerik points have been updated for bringing this omission to our attention. Do let us know if you notice other problems/inconsistencies.

Greetings,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Paul Bacci
Top achievements
Rank 1
Answers by
Paul Bacci
Top achievements
Rank 1
Ed
Top achievements
Rank 1
Steve
Telerik team
Share this question
or