Passing value to report parameter

8 posts, 0 answers
  1. Brian
    Brian avatar
    21 posts
    Member since:
    Jul 2013

    Posted 19 Nov 2014 Link to this post

    I have a report viewer on my asp.net page and its ReportSource.TypeName is set to the .vb file of my report.  My .vb report has a parameter and I need to pass in a value to it.  The report viewer has its own parameters but these seem to be different than the report's parameters as compiled in the .vb code.  How do I pass a value to the report?  

    I have looked through the Telerik documentation and I do not see how to do this.  
  2. Nasko
    Admin
    Nasko avatar
    1071 posts

    Posted 21 Nov 2014 Link to this post

    Hello Brian,

    Values can be passed to the report parameters via the TypeReportSource.Parameters collection. For more information and samples, please refer to the TypeReportSource Class article.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Brian
    Brian avatar
    21 posts
    Member since:
    Jul 2013

    Posted 22 Nov 2014 in reply to Nasko Link to this post

    Nasko,

    Thank you for this information.  I feel like I must be missing something fundamental as this is not working for me.  

    There are parameters in the report viewer and there are parameters in the report designer.  I can not seem to assign values to parameters in the report viewer (with TypeReportSource.Parameters) and then have the content generated from the report designer "see" those values and use them.

    For example, I'm trying to pass an "Account" value.  If I create an Account parameter in the viewer and the designer, the designer ignores the value I set in the viewer.  If I only have an Account parameter in the viewer and remove it from the designer, then the report errors because it does not have an Account parameter.  I have no problem creating and setting a parameter value in the viewer but I can't seem to get any external values into the report designer and use them.  
  4. Brian
    Brian avatar
    21 posts
    Member since:
    Jul 2013

    Posted 22 Nov 2014 in reply to Brian Link to this post

    Nasko,

    To clarify, here is the code I'm using in the Load event on the page.  rptInvoice is the viewer control.

    typeReportSource.TypeName = GetType(Invoice).AssemblyQualifiedName
    typeReportSource.Parameters.Add(New Telerik.Reporting.Parameter("Account", "CustomerNameHere"))
    rptInvoice.ReportSource = typeReportSource

    Within the Invoice designer, whether I do or do not have an Account parameter, the value is not set.  If I set a default value in the designer, that value is used.  If I do not include a parameter in the designer, I get an error that there the Account parameter is missing (it's used in the SQL to generate the invoice)
  5. Nasko
    Admin
    Nasko avatar
    1071 posts

    Posted 26 Nov 2014 Link to this post

    Hello Brian,

    Check the attached project which is demonstrating how to pass a value to the report parameters in your report.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. JOSE BERNARDO
    JOSE BERNARDO avatar
    1 posts
    Member since:
    May 2014

    Posted 12 Mar 2015 Link to this post

    Hello , 
    I have the same issue related to this post but for MVC 4 . I'm using the ReportViewer Widget and  VS reports . I tried to replicate the code in the attached project but I think I'm missing something since I can get passed the parameter to report. Please see code below and let me know If there is something else I need to do. 

    Thanks in Advance.

    //View
    @model RH4000.Models.Reporting.ReportViewerViewModel
    @{
        Layout = "~/Views/Shared/_ReportingLayout.cshtml";
    }
    @(Html.TelerikReporting().ReportViewer()
            .Id("reportViewer")
            .ServiceUrl("/api/reports/")
            .TemplateUrl(Model.TemplateUri)
            .ReportSource(Model.TReportSource)
            .ViewMode(ViewModes.INTERACTIVE)
            .ScaleMode(ScaleModes.SPECIFIC)
            .Scale(1.0)
            //.PersistSession(false)
     
    )


    //Controller
    public
    ActionResult Index()
           {
               ReportViewerViewModel model = (ReportViewerViewModel)TempData["ReportSourceModel"];
               return View(model);
           }
     
           [HttpPost]
           public ActionResult PrePayrollMovements(FormCollection collection)
           { 
               TempData["ReportSourceModel"] = CreateReportSource(typeof(PreMovementsReport));
               return RedirectToAction("Index", "Report");
           }
     
           private static ReportViewerViewModel CreateReportSource(Type objType)
           {
               var reportSourceModel = new ReportViewerViewModel();
               reportSourceModel.TemplateUri = ConfigurationManager.AppSettings["ReportingTemplate"] ?? "/Content/templates/telerikReportViewerTemplate-8.2.14.1204.html";
               reportSourceModel.TReportSource = new TypeReportSource();           
               reportSourceModel.TReportSource.TypeName = objType.AssemblyQualifiedName;
               reportSourceModel.TReportSource.Parameters.Add(new Telerik.Reporting.Parameter("PeriodID", "ab6f36d6-1831-4711-ba73-704501470bc7"));          
               return reportSourceModel;
           }




    //Report Api
    public class ReportsController : ReportsControllerBase
        {
            protected override IReportResolver CreateReportResolver()
            {
                var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");
                return new ReportTypeResolver().AddFallbackResolver(new ReportTypeResolver());           
            }
            protected override ICache CreateCache()
            {
                return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache();
            }
        }

  7. Nasko
    Admin
    Nasko avatar
    1071 posts

    Posted 16 Mar 2015 Link to this post

    Hello Jose,

    There is a known issue caused by external libraries where the parameter values will not be passed from the report viewer to the report using the HTML5 Report Viewer in some scenarios. This issue is caused by using an old version of the Newtonsoft.Json assembly. Please open your project and check for updates for the Newtonsoft.Json.dll via NuGet.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Boris
    Boris avatar
    7 posts
    Member since:
    Apr 2014

    Posted 14 Sep 2018 Link to this post

    Hi i am getting similar problem,  i send in the parameter, but value never gets there...

    I am using latest Newtonsoft.Json

Back to Top