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

Expression not recognizing my user defined function

6 Answers 354 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 14 Apr 2009, 09:47 PM
I have created a user-defined function that I'm trying to use in an expression to pass to a parameter for a sub-report, but no matter what I do, I continue to get the error "The expression contains undefined function call AddDays()."

Here is my function:
    Public Shared Function AddDays(ByVal dateToModify As Date, ByVal days As Double) As DateTime
        Return dateToModify.AddDays(days)
    End Function

The parameter in my subreport is called "FromDate".  In my main report, I'm trying to set the value of the subreport parameter to this:
=(MyClassName).Utils.AddDays(Now(), 1)

This causes the error every time.  If I just set it to Now() it works (but of course I don't want this).  My function shows up in the list of available user functions in the expression editor.  I have other functions that work just fine.  This one doesn't.

Regards,
Scott

BTW, I'm using Reporting Q3 2008

6 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 17 Apr 2009, 08:19 AM
Hello Scott,

There are three cases in which you might get this error message.

  • If you have typed in the function manually without rebuilding the class library and therefore it does not exist.
  • If the expression does not match the function signature you've defined e.g. you are trying to use the function with wrong number of parameters or they are of different type.
  • If the field you specify in the function is null for some reason. Make sure you handle such cases in your user function.
In your case it is #2. Your second parameter is of type double, but you're passing int to it. You can change the double to integer and it would work as expected.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Scott
Top achievements
Rank 1
answered on 22 Apr 2009, 03:20 AM
Okay, but I was explicitly calling my function "=Utils.AddDays(Now(), 1)" with a value of "1", which was not a declared integer, it was a hard-coded value.  Why is "1" not recognized as Double by the Telerik Reporting engine?  I entered "1.0" and got the same error.

To test, I created another function, "AddDays2(dateToModify As DateTime)" which returned "dateToModify.AddDays(1)", and that worked without any problems (where the "1" is not a declared Integer or Double).  The .NET DateTime.AddDays function accepts the "1" without any trouble, and without me declaring it as Double or converting it to double.

I did get my AddDays function to work by calling it "=Utils.AddDays(Now(), CDbl(1))", but definitely puzzled as to why I should even have to convert it (using "CDbl') to begin with.
0
Steve
Telerik team
answered on 22 Apr 2009, 12:53 PM
Hello Scott,

Yes, the .NET runtime would differentiate properly in such scenario, but it is not the C# compiler doing this in our expression editor and when you pass 1.0 it is considered as float - that is why an explicit cast to double is needed and that is why I suggested an easier solution.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Scott
Top achievements
Rank 1
answered on 22 Apr 2009, 12:56 PM
Sounds good.  Thanks for clarifying what is happening!
0
Yuvika
Top achievements
Rank 1
answered on 09 Jan 2010, 11:02 AM
Hi,

I am also not able to access the function in reports.
public static string GetFormatedDecimalValues(string value)  
        {  
            try 
            {  
                CultureInfo currentCulture;  
                currentCulture = System.Globalization.CultureInfo.CurrentUICulture;  
                decimal dVal = decimal.Parse(value, NumberStyles.Float);  
                string str = "";  
                //Change the format of string according to show decimal or not.                 
                str = dVal.ToString("#,#0.00", currentCulture);  
                return str;  
            }  
            catch 
            {  
                return value;  
            }  
        } 
This is my function on page.
This  is how I am using the function to format textbox.

= GetFormatedNonDecimalValues(((Sum(CustodianFileSize))/(1024*1024))) 

The error page has been attached. Please review it and let me know where I am going wrong. I have the latest version of telerik controls including the reporting tool.
Please help.

Thanks
Yuvika
0
Mike
Top achievements
Rank 1
answered on 05 Mar 2021, 01:28 PM
Appears that you you are calling GetFormatedNonDecimalValues instead of GetFormatedDecimalValues.  Note the call to your function contains "Non" but the actual function name does not.
Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Steve
Telerik team
Scott
Top achievements
Rank 1
Yuvika
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Share this question
or