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

User Function error caused by null value

3 Answers 188 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan Emptage
Top achievements
Rank 1
Ryan Emptage asked on 26 Feb 2009, 02:29 PM
Hi

I'm trying to apply some custom date formatting.
So I have created a method to format the date (where parameter dt is the Field from the database)

public static string FormatDate(DateTime dt) 
        { 
            string newDt = ""
 
            if (dt != null
            { 
                string oid = waSessionState.Current(HttpContext.Current).oid; 
                waOrganisation org = (waOrganisation)HttpContext.Current.Cache[oid]; 
                newDt = dt.ToString(org.DateFormat); 
            } 
             
            return newDt; 
        } 

And for the expression I wrote:

=waMemberDetailsReport.Utilities.FormatDate(IsNull(Fields.[MemberDateRegistered], null)) 

If a DBNull value is returned from the database then I get the error "The expression contains undefined function call FormatDate()."

I don't understand why the error is occuring when I am using the IsNull() function.

3 Answers, 1 is accepted

Sort by
0
Ryan Emptage
Top achievements
Rank 1
answered on 26 Feb 2009, 03:11 PM
I don't need an answer to this now. In case anyone else may run into the same problem, here is my simple solution....

By using the CStr() function to convert the Date field to a string and pass that string to my FormatDate() method.

As so:

FormatDate(CStr(Fields.[MemberDateRegistered])) 

I also had to change the FormatDate() method as it was now dealing with a string instead of a DateTime.
As so:

public static string FormatDate(string dt) 
        { 
            string newDt = ""
 
            if (dt != null
            {    
                string oid = waSessionState.Current(HttpContext.Current).oid; 
                waOrganisation org = (waOrganisation)HttpContext.Current.Cache[oid]; 
                newDt = DateTime.Parse(dt).ToString(org.DateFormat); 
            } 
             
            return newDt; 
        } 







0
Patrick Saunders
Top achievements
Rank 1
answered on 14 Mar 2013, 11:07 PM
just wanted to say thanks to Ryan, I had same issue, "Unknown function name" , only because i passed a dull dateTime as a parameter.
Seems quite retarded actually that it cannot cope with a null datetime.

Pat.
0
Calvin
Top achievements
Rank 1
answered on 11 Jul 2013, 09:48 PM
I had a similar problem and the error message turned out to be misleading.  The cause of the problem was not due to an "unknown user function" but rather to passing a parameter of the wrong data type.  
Tags
General Discussions
Asked by
Ryan Emptage
Top achievements
Rank 1
Answers by
Ryan Emptage
Top achievements
Rank 1
Patrick Saunders
Top achievements
Rank 1
Calvin
Top achievements
Rank 1
Share this question
or