Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display a Crystal Report object in a web page?

Status
Not open for further replies.

TheBugSlayer

Programmer
Sep 22, 2002
887
US
All,
I am designing some reports with Crystal Report 8.0.1.0 which I need to publish on the web. Can anyone tell me how to view a Crystal Report object in a web page using ASP/HTML?

Thanks in advance.

PS: By the way, it had been such a long time from I last used CR that I learnt yesterday only that the product no longer belongs to Seagate but Crystal Decisions, and that's what tehy call version 9 now...
 
SpiderBear6,
thanks for your reply. I have one or two questions.

You can use the CRViewer object, like this...

<OBJECT ALIGN = Center ID=&quot;CRViewer&quot; WIDTH=100% HEIGHT=100%
CLASSID = &quot;CLSID:C4847596-972C-11D0-9567-00A0C9273C2A&quot;
CODEBASE=&quot;<PARAM NAME=&quot;Report Name&quot; VALUE=&quot;rptserver.asp&quot;>
<PARAM NAME=&quot;Show Group Tree&quot; Value=0>
<PARAM NAME=&quot;Show Toolbar&quot; VALUE=1>
<PARAM NAME=&quot;Has Group Tree&quot; VALUE=0>
<PARAM NAME=&quot;Has Navigation Control&quot; VALUE=1>
<PARAM NAME=&quot;Has Stop Button&quot; VALUE=1>
<PARAM NAME=&quot;Has Print Button&quot; VALUE=1>
<PARAM NAME=&quot;Has Zoom Control&quot; VALUE=1>
<PARAM NAME=&quot;Has Close Button&quot; VALUE=0>
<PARAM NAME=&quot;Has Progress Control&quot; VALUE=1>
<PARAM NAME=&quot;Has Search Button&quot; VALUE=1>
<PARAM NAME=&quot;Has Refresh Button&quot; VALUE=1>
<PARAM NAME=&quot;Can Drill Down&quot; VALUE=1>
<PARAM NAME=&quot;Has Animation Control&quot; VALUE=1>
</OBJECT>


Above is the code you posted in the ASP forum. Is 'rptserver.asp' the name of the CR report to be displayed? My I create the report in CR and it isn't an ASP file but a .rpt. I would appreciate your prompt response.

Just to be sure, you have preferred to place the DLL on the server so it's accessible to every client, right? Otherwise clients who don't have the DLL won't be able to view the report...
 
Sorry I forgot I had created separate asp pages to do some of the work...

I did find this in another forum... might be useful.

First of all, you will need to create an HTML page(you might already done this) and take the user input, and secondly you will have do a Form Action to redirect to create an ASP page where you can call the report through Crystal Report RDC(Report Designer Component) automation server, and passing in the parameters that you've got from the HTML page.

My following example has this report that has two parameters, first is country, and second is a string. Then I've create a selection formula in Crystal which has:
{Customer.Country} = {?Country}
and then I put the other parameter to the Report header as a report title.

From my HTML page I've create two type of parameter, a drop-down list parameter, and then a user typing-in-value kind of parameter. In the form action of this page, I am calling the ASP page where it pasisng the two parameters taken from this HTML page. And then I will view the report in the ActiveX Viewer. Here are my two pages:
for HTML, here is what I have:
<html>
<title>Parameter Field Sample</title>
<body>
<form method=&quot;POST&quot; action=&quot;ParameterFields.asp&quot;>
<p><select name=&quot;SelectedCountry&quot; size=&quot;1&quot;>
<option selected>USA</option>
<option>Canada</option>
<option>UK</option>
<option>France</option>
<option>Italy</option>
<option>Holland</option>
</select></p>
<FONT face=&quot;Arial&quot; size=2>
Note: Netscape Plug-in Report Viewer works only with Netscape Navigator 4.x browser.
<BR>
<BR>
<b><font size=&quot;2&quot;>Add a Title to the Report</font></b><BR>
<p><input type=&quot;text&quot; name=&quot;TitleString&quot; size=&quot;53&quot; value=&quot;Report Title&quot;><BR>
<br>
<input type=&quot;submit&quot; value=&quot;Get Report&quot;>
</body>
</html>

For the ASP page, here is what I've got:
<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>

<%
reportname = &quot;ParameterFields.rpt&quot;

' CREATE THE APPLICATION OBJECT
If Not IsObject (session(&quot;oApp&quot;)) Then
Set session(&quot;oApp&quot;) = Server.CreateObject(&quot;CrystalRuntime.Application&quot;)
End If

' CREATE THE REPORT OBJECT
Path = Request.ServerVariables(&quot;PATH_TRANSLATED&quot;)
While (Right(Path, 1) <> &quot;\&quot; And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend

'OPEN THE REPORT (but destroy any previous one first)
If IsObject(session(&quot;oRpt&quot;)) then
Set session(&quot;oRpt&quot;) = nothing
End if

Set session(&quot;oRpt&quot;) = session(&quot;oApp&quot;).OpenReport(path & reportname, 1)

'This line uses the &quot;PATH&quot; and &quot;reportname&quot; variables to reference the Crystal
'Report file, and open it up for processing.

session(&quot;oRpt&quot;).MorePrintEngineErrorMessages = False
session(&quot;oRpt&quot;).EnableParameterPrompting = False

'force report to refresh:
session(&quot;oRpt&quot;).DiscardSavedData

'====================================================================================
' Insert the value for the Crystal Report Parameter Field
'====================================================================================

set session(&quot;ParamCollection&quot;) = Session(&quot;oRpt&quot;).Parameterfields
'This line creates an object to represent the collection of parameter
'fields that are contained in the report.
'create the parameter field for {?Country} parameter:
set Param1 = session(&quot;ParamCollection&quot;).Item(1)

'create the parameter field for {?Title} parameter:
set Param2 = session(&quot;ParamCollection&quot;).Item(2)

'get the user input for the country:
ParamValue = Request.Form(&quot;SelectedCountry&quot;)
'pass it to the report:
Call Param1.SetCurrentValue (CStr(ParamValue), 12)

'get the user input for the report title:
ParamValue = Request.Form(&quot;TitleString&quot;)
'pass it to the report:
Call Param2.SetCurrentValue (CStr(ParamValue), 12)

'This line calls the SetCurrentValue method of the parameter field
'object to give the parameter field the value of the ParamValue variable.
'
'The first parameter passed to the SetCurrentValue method is the value
'that you want to pass to the Crystal Reports parameter field. The
'second parameter is the datatype of the value you are passing to the
'Crystal Parameter field.

'Since we are passing a VBScript variable as the value for the parameter
'we must cast the variable as the proper datatype before passing it to
'the report. This is because VBScript variables are not datatyped unless
'cast.

'Below is a list of Crystal Data types, the VBScript cast functions and
'data type qualifier parameter to pass to the SetCurrentValue method:

' Param Field Type VBScript Call Type Number
'
' NumberField CDbl 7
' CurrencyField CDbl 8
' Boolean CBool 9
' StringField CStr 12

'*Note* that you can not use the CDate() function to cast a variable as
'a VB Date type, then qualify that variable as type number 10 to pass
'the value as a Crystal Date. This is because a VB Date and a Crystal
'Date type are not the same. The best solution is to pass the date value
'to the Crystal Parameter field as a string type and convert the strng
'to a date in Crystal Reports using a Crystal Formula Field.

'====================================================================================
' Retrieve the Records and Create the &quot;Page on Demand&quot; Engine Object
'====================================================================================

On Error Resume Next
session(&quot;oRpt&quot;).ReadRecords
If Err.Number <> 0 Then
Response.Write &quot;An Error has occured on the server in attempting to access the data source&quot;
Else

If IsObject(session(&quot;oPageEngine&quot;)) Then
set session(&quot;oPageEngine&quot;) = nothing
End If
set session(&quot;oPageEngine&quot;) = session(&quot;oRpt&quot;).PageEngine
End If

' INSTANTIATE THE CRYSTAL REPORTS SMART VIEWER
%>
<HTML>
<HEAD>
<TITLE>Seagate ActiveX Viewer</TITLE>
</HEAD>
<BODY BGCOLOR=C6C6C6 LANGUAGE=VBScript ONLOAD=&quot;Page_Initialize&quot;>

<OBJECT ID=&quot;CRViewer&quot;
CLASSID=&quot;CLSID:C4847596-972C-11D0-9567-00A0C9273C2A&quot;
WIDTH=100% HEIGHT=95%
CODEBASE=&quot;/viewer/activeXViewer/activexviewer.cab#Version=8,0,0,224&quot;>
<PARAM NAME=&quot;EnableRefreshButton&quot; VALUE=1>
<PARAM NAME=&quot;EnableGroupTree&quot; VALUE=1>
<PARAM NAME=&quot;DisplayGroupTree&quot; VALUE=1>
<PARAM NAME=&quot;EnablePrintButton&quot; VALUE=1>
<PARAM NAME=&quot;EnableExportButton&quot; VALUE=1>
<PARAM NAME=&quot;EnableDrillDown&quot; VALUE=1>
<PARAM NAME=&quot;EnableSearchControl&quot; VALUE=1>
<PARAM NAME=&quot;EnableAnimationControl&quot; VALUE=1>
<PARAM NAME=&quot;EnableZoomControl&quot; VALUE=1>
</OBJECT>

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Sub Page_Initialize
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject(&quot;WebReportBroker.WebReportBroker&quot;)
if ScriptEngineMajorVersion < 2 then
window.alert &quot;IE 3.02 users on NT4 need to get the latest version of VBScript or install IE 4.01 SP1. IE 3.02 users on Win95 need DCOM95 and latest version of VBScript, or install IE 4.01 SP1. These files are available at Microsoft's web site.&quot;
CRViewer.ReportName = &quot;rptserver.asp&quot;
else
Dim webSource
Set webSource = CreateObject(&quot;WebReportSource.WebReportSource&quot;)
webSource.ReportSource = webBroker
webSource.URL = &quot; webSource.PromptOnRefresh = True
CRViewer.ReportSource = webSource
end if
CRViewer.ViewReport
End Sub
-->
</SCRIPT>

</BODY>
</HTML>


:)
 
Hi SpiderBear6 ,
Maybe I missed something in your thread, but I still see nothing that explains what rptserver.asp
contains...It is not one of the 2 files you listed.

[profile]
 
QUESTION:
What happens if the parameters are set in ASP,
yet the parameter "prompt" still appears?
(This is visible after the line: CRViewer.ShowReport)

Rgds,
Wayne.
 
This was such a long time ago I don't remember a thing. Maybe the other guys can help u. Sorry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top