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

Userfunctions not found in ReportBook.

2 Answers 96 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 25 Mar 2011, 11:28 AM
Hi I'm working on a webproject and using telerik reporting to display custom reports.

I have the following Solution Structure..

-Solution
 + Web Project (Web)
 + Class Library (Reports)

I have designen a report that takes dynamic parameters and builds multivalue parameters from what has prev been selected.

So in the report i have a first parameter Page, page is not a multivalue. When a page is selected say you select ID 5, the second parameter takes the selected value and calls and stored procedure with the first parameters value as a parameter passed to the sp. Here everything is ok. However when it comes to the second parameter which is a multivalue. I have choosen so that the third parameter takes the selected values of the second and calls an sp with the values. To get the values i am using a userfunction like below
public static string FormatArray(object[] array)
       {
           StringBuilder sb = new StringBuilder();
           foreach (object o in array)
           {
               if (sb.Length > 1)
               {
                   sb.Append(", ");
               }
               sb.Append(o.ToString());
           }
           return sb.ToString();
       }

In the Report Preview & Html Preview this works perfect and everything is displayed and bound as it should be..

However when migrating this report to my web solution I have the following setup.

Enheter.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Enheter.ascx.cs" Inherits="Web.controls.Reports.Enheter" %>
<%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=5.0.11.316, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"
    Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>
<telerik:ReportViewer ID="ReportViewer1" runat="server" Width="100%" Height="700px"
   >
</telerik:ReportViewer>



Backend

 
Report myReport = new Rapporter.K2.Report1();
 
                myReport.ReportParameters["nkod"].Value = nkod;
                myReport.ReportParameters["sysID"].Value = BaseLogic.GlobalSystemID.intSystemID;
                using (CoreEntities db = new CoreEntities(clsBaseLogic.SqlConnEntityString))
                {
                    myReport.ReportParameters["strEnhet"].Value = db.tblTree_item.SingleOrDefault(k => k.intTreeItemID == nkod).strTreeItem;
                    myReport.ReportParameters["strPeriod"].Value = db.tblCore_Period.SingleOrDefault(k => k.intPeriodID == BaseLogic.intPeriodID).strDescription;
 
                }
                ReportBook book = new ReportBook();
                book.Reports.Add(myReport);
                ReportViewer1.Report = book;


This is just because I want to set some parameters before making the report..


Everything shows up as it should but when trying to select a value inside my second parameter , the third parameter who uses my userfunction displays the following error.

The expression contains undefined function call FormatArray().
 
at Telerik.Reporting.Expressions.FunctionNode.Eval(Object row, Object context)
at Telerik.Reporting.Processing.Data.MultidimensionalQueryProvider.Evaluate(Object value, Object data)
at Telerik.Reporting.Processing.Data.SqlQueryProvider.GetEvaluatedParameters()
at Telerik.Reporting.Processing.Data.SqlQueryProvider.GetCommandParameters(Boolean evaluateParameters)
at Telerik.Reporting.Processing.Data.SqlQueryProvider.CreateCommand(IDbConnection connection, Boolean evaluateParameters)
at Telerik.Reporting.Processing.Data.SqlQueryProvider.CreateCommand(IDbConnection connection)
at Telerik.Reporting.Processing.Data.SqlDataEnumerable.d__0.MoveNext()
at Telerik.Reporting.Processing.Data.ResultSet.SeedData(IEnumerable`1 rawData)
at Telerik.Reporting.Processing.Data.ResultSet.Fill(IEnumerable`1 data)
at Telerik.Reporting.Processing.Data.SqlQueryProvider.Execute(MultidimensionalQuery query)
at Telerik.Reporting.Processing.ParametersManager`1.GetAvailableValuesData(ReportParameterAvailableValues availableValuesDef, ExpressionNode valueExpression, MultidimensionalQueryProvider& provider)
at Telerik.Reporting.Processing.ParametersManager`1.CalculateParameterValues(T parameter, ReportParameter parameterDef, IDictionary`2 parameterValues)
at Telerik.Reporting.Processing.ParametersManager`1.Calculate(T parameter, IDictionary`2 parameterValues)
at Telerik.Reporting.Processing.ParametersManager`1.CalculateChildren(T parameter, IDictionary`2 parameterValues)
at Telerik.Reporting.Processing.ParametersManager`1.Calculate(T parameter, IDictionary`2 parameterValues)
at Telerik.Reporting.Processing.ParametersManager`1.CalculateChildren(T parameter, IDictionary`2 parameterValues)
at Telerik.Reporting.Processing.ParametersManager`1.Calculate(T parameter, IDictionary`2 parameterValues)
at Telerik.Reporting.Processing.ParametersManager`1.GetParameters(IDictionary`2 parameterValues)
at Telerik.ReportViewer.WebForms.ParametersPage.OnLoadComplete(EventArgs e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

the third parameter datasource is an sp with the following parameters inserted -> = FormatArray(Parameters.survFieldsGroup.Value)
Parameters.survFieldsGroup being the second parameter.

It seems the report doesnt know where the userfunction is when it has been migrated to the reportbook.

How can i fix this?

Anders

2 Answers, 1 is accepted

Sort by
0
Anders
Top achievements
Rank 1
answered on 28 Mar 2011, 07:20 AM
Located that this problem only applies to userfunctions used within parameters.
0
Peter
Telerik team
answered on 31 Mar 2011, 02:07 PM
Hello Anders,

You will have to create your own ReportBook class in the same assembly where the User Function resides. Your ReportBook should inherit Telerik.Reporting.ReportBook type as shown in the following code snippet and in our demos that came with your installation of Telerik Reporting:

[Description("A collection of Product-related reports")]
public class ReportBook : Telerik.Reporting.ReportBook
{
    public ReportBook()
    {
        this.Reports.Add(new DashBoard());
        this.Reports.Add(new ProductSales());
    }
}
Then from your application you can access the Report Parameters from the ReportBook.Reports collection as illustrated in the code snippet:
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        var reportBook = new Telerik.Reporting.Examples.CSharp.ReportBook();
        reportBook.Reports[0].ReportParameters["strEnhet"].Value = "my value";
        this.ReportViewer1.Report = reportBook;
    }
}

The final step is to specify the user function with the full name of the type to which it belongs (see Assembly scoped user functions in the User Functions topic). For example:

instead of:

[ReportParameter].Value = "=Qtr(Now())";

it should be:
[ReportParameter].Value = "=Telerik.Reporting.Examples.CSharp.DashBoard.Qtr(Now())";

All these steps are needed because of the way the user functions are resolved. The functions should be in the same assembly in which the report/reportbook is defined. When you are using the Telerik.Reporting.ReportBook class then the owner assembly is Telerik.Reporting which does not contain any user functions.

Hope this helps.

Regards,
Peter
the Telerik team
Tags
General Discussions
Asked by
Anders
Top achievements
Rank 1
Answers by
Anders
Top achievements
Rank 1
Peter
Telerik team
Share this question
or