# User Function

1. ##### Mashran
2 posts
Member since:
Oct 2014

Posted 08 Oct 2014 Link to this post

Hi, I have create a function

public static double CallAge(string _status, string _sDate, string _eDate, string _last_update, string _report_datetime, string _total_holiday, string _total_hour)
{
if (_status == "6" || _status == "5" || _status == "4")
{
double Dys = 0, SatDys = 0, SunDys = 0;
DateTime d1, d2, dateLastUpdate;
TimeSpan timesp;
d2 = Convert.ToDateTime(_eDate);
d1 = Convert.ToDateTime(_report_datetime);
dateLastUpdate = Convert.ToDateTime(_last_update);
if (d2 < dateLastUpdate)
{
timesp = (d2 - d1);
Dys = timesp.Seconds;
SatDys = findWeekCount(d1, d2, DayOfWeek.Saturday);
SunDys = findWeekCount(d1, d2, DayOfWeek.Sunday);
if (Dys > 0)
{
Dys = Dys - (checkHoliday(_total_holiday) + SatDys + SunDys) * 86400;
Dys = Dys - (timesp.Days - SatDys - SunDys - checkHoliday(_total_holiday) * Convert.ToDouble(_total_hour));
Math.Abs(Dys);
return Dys;
}
else
{
return 0;
}
}
else
{
d2 = Convert.ToDateTime(_last_update);
d1 = Convert.ToDateTime(_report_datetime);
timesp = (d2 - d1);
Dys = timesp.Seconds;
SatDys = findWeekCount(d1, d2, DayOfWeek.Saturday);
SunDys = findWeekCount(d1, d2, DayOfWeek.Sunday);
if (Dys > 0)
{
Dys = ((checkHoliday(_total_holiday) + SatDys + SunDys) * 86400) - Dys;
Dys = Dys - ((timesp.Days - SatDys - SunDys - checkHoliday(_total_holiday) * Convert.ToDouble(_total_hour)));
Math.Abs(Dys);
return Dys;
}
else
{
return 0;
}
}
}
else
{
return 0;
}
}

How to get field from store procedure?
I try like this on Expression Editor :

=TicketAge(Fields.STATUS,Parameters.sDate.Value,Parameters.eDate.Value,Fields.LAST_UPDATE,Fields.REPORT_DATETIME,Fields.TOTAL_HOLIDAY,Fields.TOTAL_HOUR)

But it display error : An error has occurred while processing TextBox 'textBox25': The expression contains undefined function call TicketAge().

2. ##### KS
165 posts
Member since:
Oct 2012

Posted 13 Oct 2014 in reply to Mashran Link to this post

Hi,

Check this info - The expression contains undefined function call MyUserFunction() error. I believe it is the 3rd reason, and not all or some of the arguments are not of the expected type or are null.

-KS
3. ##### Mashran
2 posts
Member since:
Oct 2014

Posted 14 Oct 2014 in reply to KS Link to this post

Hi KS,

thanks for reply, and already solve my problem. The problem was came from datatype in database not match with datatype in user function.

public static double CallAge(string _status, string _sDate, string _eDate, string _last_update, string _report_datetime, string

change to

public static double CallAge(string _status, string _sDate, string _eDate, DateTime _last_update, DateTime _report_datetime, string

Thanks a lot :)