User Functions

4 posts, 0 answers
  1. Paul Bacci
    Paul Bacci avatar
    9 posts
    Member since:
    Sep 2004

    Posted 23 Sep 2009 Link to this post

    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().
  2. Paul Bacci
    Paul Bacci avatar
    9 posts
    Member since:
    Sep 2004

    Posted 23 Sep 2009 Link to this post

    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.
  3. DevCraft banner
  4. Ed
    Ed avatar
    9 posts
    Member since:
    Jun 2010

    Posted 29 Sep 2010 Link to this post

    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.
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Oct 2010 Link to this post

    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
Back to Top