Viewing Reports

Naturally, simply printing out a list of reports isn all that useful if they can be viewed. This section focuses on viewing reports. Report viewing is also done via the Crystal Enterprise SDK, specifically, through an object called the CrystalReportViewer. This viewer object, like the other SDK objects, resides on the server. Its job is to render reports to a paginated HTML output. Generally, an ASP page is created and this page is passed in some kind of identifier to determine which report to display (see Listing 34.14).

Listing 34.14. Viewing a Report in HTML

<%

 Logon

Set sessMgr = Server.CreateObject("CrystalEnterprise.SessionMgr")

Set sess = sessMgr.Logon("Ryan", "123", "CMS1", "secEnterprise")



 Get the name of the report from the query string

reportID = Request.QueryString("reportID")



 Retrieve the report source object given the ID

Set reportSource = sess.Service("", "PSReportFactory").OpenReportSource(reportID)



 Create and set up the viewer object

Set viewer = CreateObject("CrystalReports.CrystalReportViewer")

viewer.EnterpriseLogon = sess

viewer.ReportSource = reportSource



 Instruct the viewer to render the HTML output into the response stream

viewer.ProcessHttpRequest Request, Response



%>


The first part of Listing 34.13 establishes a session to Crystal Enterprise. The second part then extracts the reportID item off the query string and stores it in the reportID variable. Next, like the InfoStore, the PSReportFactory is retrieved via the EnterpriseSession object. The PSReportFactory (or Page Server Report Factory) is an object that represents the Page Server service. It has an OpenReportSource method that takes the report ID as an argument. When this method is invoked, the page server opens the report and loads it ready for processing. Next, the CrystalReportViewer object is created and two things are passed into it: the active Crystal Enterprise session, and the reportSource object, which represents the report the page server has open. Finally, the ProcessHttpRequest method of the viewer object is called, which instructs the Page Server to execute the first page of the report and return its output. The viewer then converts that output into HTML and writes that into the pages response stream. The end result is a page with the first page of the report displayed. Figure 34.2 shows the output of one of the sample reports.

Figure 34.2. The output of Listing 34.14 shows a report displayed in HTML.

graphics/34fig02.jpg


NOTE

When querying the InfoStore for a given report by name, if you want only report objects and not report instances, include the WHERE SI_INSTANCE=0 condition in the query. This tells the InfoStore to only bring back reports that are not instances. Remember, the report keeps the same name when its scheduled.


Because the report output can be written anywhere into the response stream, many possibilities of report presentation are available. Sometimes the only content on an ASP page is a report, other times it can be residing along with page headers, footers, navigation panels, or other images and text.






Special Edition Using Crystal Reports 10
Special Edition Using Crystal Reports 10
ISBN: 0789731134
EAN: 2147483647
Year: 2003
Pages: 341
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net