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 = "<%=Server.UrlEncode("&") %>"
var progid="CrystalEnterprise.Report"
if (f == 1) {
var pstr = amper + "promptex-EmpNbr=" + p
}
if (f == 2) {
var pstr = amper + "promptex-jcode=" + p
}
windowprops = "fullscreen=no,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes";
reportWindow = window.open("empviewer.csp?qid=" + pstr + "&progid=" + progid + "&rid=" + m,"rptWindow",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="setcodepage.csp" -->
<!-- #include file="helper_js.csp" -->
<script language=Javascript>
function init()
{
document.forms["redirForm"].submit();
}
</script>
</head>
<body onload=init()>
<%
var action, tokenName;
var progid = Request.QueryString.Item("progid");
if(progid = "CrystalEnterprise.Report" )
{
action = "viewrpt.cwr?id=" + Request.QueryString.Item("rid") + Request.QueryString.Item("qid") + "&init=actx" + Server.URLEncode(":connect");
tokenName = "apstoken";
}
else
{
action = "infoobject.cwr?id=" + Request.QueryString.Item("id") + "&action=0";
tokenName = "WCSLOGONTOKEN";
}
Response.Write("<form name='redirForm' method='post' action='" + action + "'>\n");
Response.Write("<input type='hidden' name='" + tokenName + "' value=\"" + Server.HTMLEncode(GetCookie("logontoken")) + "\">\n");
Response.Write("</form>\n");
%>
</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] = '"' + picks.options[i].value + '"'
indx++
}
}
str3 = choices.join(",")
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="button" title="Basic Contact Info" style="text-align:left;color:#0000DD;background-color:#CCFFFF;width:255" VALUE="Employee Contact Info " onClick="GetData(this.form,'179',1)">
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] [profile] [profile]](/data/assets/smilies/profile.gif)