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

The expression contains undefined function call MyUserFunction() error

3 Answers 254 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
smith spd
Top achievements
Rank 1
smith spd asked on 15 Sep 2010, 05:55 PM

Hello Telerik Team,

I am getting the error."An error has occured while processing textbox:The expression contains undefined
function call FormType()".

I have a report..where in i used a user function called "FormType".
My datasource  for teh report is sharepoint list.

I am passing a parameter to the user function in the code.My user functions retrieves three values(one each time based on the conditions)But when i select the user function..in the edit expression dialog box..
i am not writing any parameter inside the user function as i am not sure what to write there.

I have gone through http://www.telerik.com/support/kb/reporting/designing-reports/the-expression-contains-undefined-function-call-myuserfunction-error.aspx
and thought i might fall in 2nd cateogry..but unable to find a solution for that

Please help me.

Here is the code.

InitializeComponent();
            string strType;
            SPSite oSite = new SPSite("spsiteurl");
            SPWeb oWeb = oSite.OpenWeb();
            string[] parameters = { "10", "100", "1000" };

            Telerik.Reporting.ReportParameter param1 = new Telerik.Reporting.ReportParameter();
            param1.Name = "ItemID";
            param1.Type = Telerik.Reporting.ReportParameterType.Integer;
            param1.AllowBlank = false;
            param1.AllowNull = true;
            param1.Text = "ItemID";
            param1.Visible = true;
           

            this.ReportParameters.Add(param1);

            SPQuery qry = new SPQuery();
            SPList oList = oWeb.Lists["customlist"];
          

            string camlQuery = CreateCAMLQuery(parameters);

            qry.Query = camlQuery;

            SPListItemCollection listItemsCollection = oList.GetItems(qry);

            StringBuilder sb1 = new StringBuilder();
           
                  for (int i = 0; i < parameters.Length; i++)
                {
                    foreach (SPListItem item in listItemsCollection)
                    {
                        if (parameters[i] != "")
                        {
                            sb1 = new StringBuilder();
                            if (parameters[i] == item["ItemID"].ToString())
                            {
                                sb1.Append(parameters[i].ToString() + "-" + item["FormType"].ToString() + ",");
                                strType = FormType(sb1.ToString());
                                break;
                            }
                        }
                    }

                  
                  
                }
 DataTable listItemsTable = oList.GetItems(qry).GetDataTable();
            this.DataSource = listItemsTable;

  }

        private static string CreateCAMLQuery(string[] parameters)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < parameters.Length; i++)
            {
                if (i >= 2 && !sb.ToString().EndsWith(@"</Or>"))
                {
                    sb.Insert(0, "<Or>");
                    sb.Insert(sb.Length, "</Or>");
                }

                sb.Append("<Eq>");
                sb.Append("<FieldRef Name='ItemID'/>");
                sb.AppendFormat("<Value Type='Choice'>" + parameters[i] + "</Value>", i);
                sb.Append("</Eq>");

                if (i >= 2 && !sb.ToString().EndsWith(@"</Or>"))
                {
                    sb.Insert(0, "<Or>");
                    sb.Insert(sb.Length, "</Or>");
                }

            }

            sb.Insert(0, "<Where>");
            sb.Append("</Where>");

            return sb.ToString();
        }

 public static string FormType(string strFormType)
        {
         
           string[] FormTypeValues = strFormType.Split(",".ToCharArray());
           string[] values = FormTypeValues[0].Split("-".ToCharArray());
           string ItemId = values[0];
           string formT = values[1];
           switch (formT)
           {
               case "PM":

                   formT = "Parking";
                   strFormType = formT;
                   break;

               case "PCO":

                   formT = "Nonparking";
                   strFormType = formT;
                   break;
           }

           return strFormType;
        }

I appreciate your support
Thank you,

Smith 

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 16 Sep 2010, 05:12 PM
Hello Smith,

You've only pasted your code here, when this error occurs when you use the user function as value for a report item. Make sure that the Field or expression you pass to the function is indeed of type string. You can use the built-in CStr() function to convert the value or expression to string if it not of this type directly in the expression i.e.

= FormType(CStr(Fields.MyStringColumn))

 or a better solution would be to do this directly in your database query.

Sincerely yours,
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
0
smith spd
Top achievements
Rank 1
answered on 17 Sep 2010, 05:55 PM

Hello Telerik Team,

Thank you for the response. I have used = FormType(CStr(strFormType)) in the edit expression box for form type field.
In my code I already declared strFormType as string.But it still says that "the expression contains object 'strFormType' that is not defined in the current context.

Please let me know how to pass "strFormType" value to the particular text box.

Thank you,
Smith

 

0
smith spd
Top achievements
Rank 1
answered on 21 Sep 2010, 04:59 PM

Hello Telerik Team,

I was able to get out of the problem. Inorder to write the case statements now I am using IIF function in the functions and writing my case statement over there instead of using the user functions.
Inorder to use case statement there, we have to use nested if..it serves the problem.
Thank you for the support.
Thank you,
Smith

Tags
General Discussions
Asked by
smith spd
Top achievements
Rank 1
Answers by
Steve
Telerik team
smith spd
Top achievements
Rank 1
Share this question
or