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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with CR 8.5 and ASP 1

Status
Not open for further replies.

HuskerKeith

Programmer
Jan 28, 2003
8
0
0
US
I'm trying to run a dynamic report, calling it from ASP. The report works/displays great, if I hard-code the ID # I'm querying the database on. How do I make it dynamic, so if I pass a value to it, it will query the database on that value?


Many thanks for any and all help given.
 
Where have you hard coded this id? In the crystal report, or in the asp page? Or in a stored procedure that the cr is using?
 
Actually, my apologies, but I did not post a follow-up. I should have. I made my report dynamic by getting the id in the asp page, and setting up my query there. I then passed the query using the querystring method. The report loads, hits the database with the SQL I pass in, and all is well.
 
HuskerKeith, can you share an exampl eof how you worked this? I am in the process of attempting the same thing and need an examlpe to follow.

Thanks
 
Hi,
We pretty much only use asp ( and csp) and javascript to provide the user interface to the CE reporting system..
I use some general code ( in a javascript function ) to call all our reports:

Code:
function RunRpt(p,m,f){
amper = &quot;<%=Server.UrlEncode(&quot;&&quot;) %>&quot;
var progid=&quot;CrystalEnterprise.Report&quot;
 if (f == 1) {
  var pstr = amper + &quot;promptex-EmpNbr=&quot; + p
 }
 if (f == 2) {
  var pstr = amper + &quot;promptex-jcode=&quot; + p
 }
  windowprops = &quot;fullscreen=no,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes&quot;;

  reportWindow = window.open(&quot;empviewer.csp?qid=&quot; + pstr + &quot;&progid=&quot; + progid + &quot;&rid=&quot; + m,&quot;rptWindow&quot;,windowprops);
}

The above code receives 3 parameters -
p is the parameter used in the report selection formula
m is the report ID and
f is a flag indicating, in this case, which of 2 drop-down boxes (on the Form presented to the user in the asp page) was used to select parameter values (One option list has employee names, the other job titles).
The flag also indicates which type of report ( employee info or Job info).
The flag and report ID are set when the user clicks on the relevant button, the parameter is set with another Javascript function to allow for a multiple-select from the drop-down list. ( code later)..
I also use the flag to determine which parameter name to create based on the report desired.
The empviewer.csp referenced in the function's open call is a page that processes the query strings and calls viewrpt.cwr - I think I got it from a CE sample:

empviewer.csp
Code:
<html>
<head>
<% @language=JavaScript codepage=65001%>
<!-- #include file=&quot;setcodepage.csp&quot; -->
<!-- #include file=&quot;helper_js.csp&quot; -->
<script language=Javascript>
function init()
{
	document.forms[&quot;redirForm&quot;].submit();
}
</script>
</head>
<body onload=init()>
<%
var action, tokenName;
var progid = Request.QueryString.Item(&quot;progid&quot;);

if(progid = &quot;CrystalEnterprise.Report&quot; )
{                  
        action = &quot;viewrpt.cwr?id=&quot; + Request.QueryString.Item(&quot;rid&quot;) + Request.QueryString.Item(&quot;qid&quot;) + &quot;&init=actx&quot; + Server.URLEncode(&quot;:connect&quot;);
        tokenName = &quot;apstoken&quot;;	
	        
}
else
{
	action = &quot;infoobject.cwr?id=&quot; +  Request.QueryString.Item(&quot;id&quot;) + &quot;&action=0&quot;;
	tokenName = &quot;WCSLOGONTOKEN&quot;;
}

Response.Write(&quot;<form name='redirForm' method='post' action='&quot; + action + &quot;'>\n&quot;);
Response.Write(&quot;<input type='hidden' name='&quot; + tokenName + &quot;' value=\&quot;&quot; + Server.HTMLEncode(GetCookie(&quot;logontoken&quot;)) + &quot;\&quot;>\n&quot;);
Response.Write(&quot;</form>\n&quot;);
%>
</body>
</html>

The method I use may be simplfied or made more complex..I have some where there are 4 drop down lists and 2 text input boxes used to gather parameter value information and just adding or removing some passed parameters to the RunRpt call can handle it ..
Here is the code I use to create a parameter string based on 1 or more options being selected from one of 2 drop-down lists.

Code:
function GetData(frm,rptnbr,flg){
var form = frm
var rnum = rptnbr
var flag = flg

// Check which Drop-Down was used and set the variable to the list of values from that list
 if (flag == 1) {
var picks = form.nbr
} else if (flag == 2) {
var picks = form.job
} 
//  The build the  String for Prompt in the report

choices =  new Array()
var indx = 0
  for (var i = 0; i < picks.length; i++ ){
    if (picks.options[i].selected == true) {
        choices[indx] =   '&quot;' +   picks.options[i].value  + '&quot;'
    indx++
    }
 }

str3 =    choices.join(&quot;,&quot;)
p = str3

RunRpt(str3,rnum,flag)
}

The button on the asp page that calls a report passes the vaules to the GetData() function..For instance for the Employee Info report:
Code:
<INPUT type=&quot;button&quot; title=&quot;Basic Contact Info&quot;  style=&quot;text-align:left;color:#0000DD;background-color:#CCFFFF;width:255&quot; VALUE=&quot;Employee Contact Info &quot; onClick=&quot;GetData(this.form,'179',1)&quot;>

This is a long posting and is not meant to indicate that this is the only (or even the best) way to use asp/csp and JavaScript to call CE published repprts, but I have found it useful as a 'template' to provide developers when designing a new application..Hope it helps..

Enjoy..

[profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top