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

ReportBook MVC - Reports with dynamic index to add

5 Answers 125 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gustavo
Top achievements
Rank 1
Gustavo asked on 04 Jul 2017, 06:31 PM
I have a list of reports that quantity should be dynamic, however I can not send via parameter to the BOOK to know how many AddReports (method) should go.

My MVC html PAGE constructor
1.var typeReportSource = new TypeReportSource() { TypeName = typeof(Tegma.CSA.TelerikReportLibary.Saida.ProtocoloBook).AssemblyQualifiedName };
2.int count = 0;
3.foreach (int itemId in myListInt32)//MY LIST INT32
4.{
5. typeReportSource.Parameters.Add("reports(" + count + ").protocoloId", itemId);
6. count++;
7.}

@(Html.TelerikReporting().ReportViewer()
 .Id("rptProtocolo")
 .ServiceUrl(Url.Content("~/api/reports"))
 .ReportSource(typeReportSource)
 .ViewMode(ViewMode.PrintPreview)
 .ScaleMode(ScaleMode.Specific)
 .Scale(1.0)
 .PersistSession(false)
 .PrintMode(PrintMode.AutoSelect)
)

 

MY BOOK CONSTRUCTOR

public ProtocoloBook()
{
 List<int> myListInt32 = new List<int>();//MY FAKE LIST - NEED WITH PARAMETER
 myListInt32.Add(2000108);
 myListInt32.Add(2000111);
 AddReports(myListInt32);
}
void AddReports(List<int> listaIdProtocolos)
{
 for (int i = 0; i < listaIdProtocolos.Count; i++)//Add equivalent with list receive
 {
  var typeReportSource = new TypeReportSource() { TypeName =   typeof(Tegma.CSA.TelerikReportLibary.Saida.ProtocoloRetirada).AssemblyQualifiedName };
  this.ReportSources.Add(typeReportSource);
 }
}

Any way to get in the constructor Make a list of Id's that I should generate the reports?

If possible with example
Thank you

5 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 05 Jul 2017, 12:07 PM
Hello Gustavo,

You can use a parameterized constructor for the ReportBook object in order to pass the number of reports or the names of reports in it.

To instantiate the ReportBook with the custom constructor you will have to use a custom resolver for the Reporting REST Service. The custom resolver's Resolve method receives the string information sent by the viewer's ReportSource (report description only) - How to Set Report Sources For Report Viewers operating via Telerik Reporting Services.

An example of a custom resolver is available here. Please note that the custom resolver is used most interactions with the report in the viewer and the resolver's Resolve method should return the same ReportBook instance on each call - Purpose and Usage of the Reporting REST Service Resolver.


I hope this helps.

Regards,
Stef
Progress Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Gustavo
Top achievements
Rank 1
answered on 07 Jul 2017, 02:46 PM

Hello Stef,

I tried to use the report's REST service with the Resolve method of the custom resolver.

But the result I got was just setting the report and setting the parameter to that, it was not what I needed.

My problem is that I get a collection of items in my VISION and I can not tell my ReportBook the value in my collection to make the LOOP of how many reports I should generate.

When I manipulate in debug time the constructor of ReportBook, I can set the list and the result is as expected:

for (int i = 0; i < myList.Count; i ++)
{
  var typeReportSource = new TypeReportSource() {TypeName = typeof(MyReport).AssemblyQualifiedName};
  typeReportSource.Parameters.Add("reports("+i+").paramId", myList[i]);
  this.ReportSources.Add(typeReportSource);
}


Within the ReportBook constructor, I need to go through the list, this is not possible through the Resolve method, as it will only configure the parameter to be used and the value that I need to fill is not received at this time.

I'm a bit disappointed with the difficulty in solving this simple problem.

If there is anything that can be done, it will be of great help.

Thank you
0
Gustavo
Top achievements
Rank 1
answered on 07 Jul 2017, 02:53 PM

rectification:

"My problem is that I get a collection of items in my VIEW and I can not CALL my ReportBook"

0
Accepted
Stef
Telerik team
answered on 10 Jul 2017, 03:13 PM
Hi Gustavo,

Please debug if the custom resolver is used and if it receives the string set as ReportSource.Report string. You will have to save the collection with custom data on the server before requesting the report, in order to use it. If you need only the count then you can submit the information in a custom string used as ReportSource.Report e.g.:

//at the cvlient or in your custom controller's action
var typeReportSource = new TypeReportSource() { TypeName = typeof(Tegma.CSA.TelerikReportLibary.Saida.ProtocoloBook).AssemblyQualifiedName +"-"+myList.Count.ToString()};//customized string description that will be handled by the custom resolver
//add client-side parameters which cannot be set in the custom resolver, as parameters are applied on top the resolved server-side ReportSource
foreach (int itemId in myList)
{
 typeReportSource.Parameters.Add("reports(" + count + ").protocoloId", itemId);
 count++;
}
 
//view
@(Html.TelerikReporting().ReportViewer()
 .Id("rptProtocolo")
 .ServiceUrl(Url.Content("~/api/reports"))
 .ReportSource(typeReportSource)
 .ViewMode(ViewMode.PrintPreview)
 .ScaleMode(ScaleMode.Specific)
 .Scale(1.0)
 .PersistSession(false)
 .PrintMode(PrintMode.AutoSelect)
)
 
///////////////////////////////
////////////////////server-side
 
//sampleReportBook class
public class ProtocoloBook: ReportBook
{
public ProtocoloBook(int protocols)
{
   AddReports(protocols);
}
void AddReports(int listaIdProtocolos)
{
 for (int i = 0; i < listaIdProtocolos; i++)
 {
  var typeReportSource = new TypeReportSource() { TypeName =   typeof(Tegma.CSA.TelerikReportLibary.Saida.ProtocoloRetirada).AssemblyQualifiedName };
  this.ReportSources.Add(typeReportSource);
 }
}
}
 
//sample custom resolver
public class MyResolver : IReportResolver
    {
       public Telerik.Reporting.ReportSource Resolve(string reportDescription)
        {        
            //handle the received custom string description
             var receivedValues = reportDescription.Split('-');
            //get the type of the object you need
             var reportBookAssemblyQualifiedName = receivedValues[0];
             var reportType = Type.GetType(reportBookAssemblyQualifiedName);
 
             //turn the received information into valid arguments for the parameterized constructor
             var reportBookConstructorParam = Int32.Parse(receivedValues[1]);
            Object[] argsToPass = {reportBookConstructorParam };
 
            //use System.Reflection to instantiate the ReportBook via custom constructor
             var reportInstance = (Report)Activator.CreateInstance(reportType, argsToPass );
             
             //return the server-side ReportSource
             return new InstanceReportSource { ReportDocument = reportInstance };           
        }
    }
 
////how the custom resolver is added in the ReportsController configuration
.....
static ReportsController()
      {
         // var appPath = HttpContext.Current.Server.MapPath("~/");
        //  var reportsPath = Path.Combine(appPath, @"..\..\..\Report Designer\Examples");
         // var resolver = new ReportFileResolver(reportsPath)
          //    .AddFallbackResolver(new ReportTypeResolver());
     
          configurationInstance = new ReportServiceConfiguration
          {
              HostAppId = "Html5DemoApp",
              Storage = new FileStorage(),
              ReportResolver = new MyResolver(),//resolver,
              //ReportSharingTimeout = 0,
              //ClientSessionTimeout = 0,
          };
      }
....


Please note that the Reporting REST Service's configuration is introduced as of Q2 2015. In older versions the custom resolver can be included through the service's CreateReportResolver method.

Regards,
Stef
Progress Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Gustavo
Top achievements
Rank 1
answered on 10 Jul 2017, 05:51 PM

Hi Stef.

Works fine,
that's great example to understand the Custom Resolver. thanks for that.

The only adjustment was type Report for type ReportBook in the code below:

//use System.Reflection to instantiate the ReportBook via custom constructor
var reportInstance = (ReportBook)Activator.CreateInstance(reportType, argsToPass );

 

Thanks a lot,

Gustavo

Tags
General Discussions
Asked by
Gustavo
Top achievements
Rank 1
Answers by
Stef
Telerik team
Gustavo
Top achievements
Rank 1
Share this question
or