Hey guys,
I'm having some trouble passing a date range to a report via the viewer. I do not seem to have any trouble with discrete parameters, just range parameters. It mostly works. I still have to ad support for multiple parameters, but that's easy.
Here is the code, please take a look and let me know what I'm missing or perhaps doing wrong. Remember, this is not the normal CE 10 SDK reference material or CE RAS 10 SDK, it's from the CE 10 Viewer's SDK (so it's a little wierd).
Thanks,
T
So here is the function in JavaScript that I have written. Please not that before I run this function I initialize the report object (rptObj) from the iStore and alos create a field container (fields) as a 'CrystalReports.Fields'. After the function I apply the new set of fields to the report source via the viewer as 'viewer.parameterFields = fields'.
Also, the table near the bottom is for troubleshooting to see just what the fields collection has in it and what the values are.
I'm having some trouble passing a date range to a report via the viewer. I do not seem to have any trouble with discrete parameters, just range parameters. It mostly works. I still have to ad support for multiple parameters, but that's easy.
Here is the code, please take a look and let me know what I'm missing or perhaps doing wrong. Remember, this is not the normal CE 10 SDK reference material or CE RAS 10 SDK, it's from the CE 10 Viewer's SDK (so it's a little wierd).
Thanks,
T
So here is the function in JavaScript that I have written. Please not that before I run this function I initialize the report object (rptObj) from the iStore and alos create a field container (fields) as a 'CrystalReports.Fields'. After the function I apply the new set of fields to the report source via the viewer as 'viewer.parameterFields = fields'.
Also, the table near the bottom is for troubleshooting to see just what the fields collection has in it and what the values are.
Code:
// gets the report parameters, sets security and mpsURL, sets other entered parameters
function getParameterFields(rptObj, fields){
//Get the report parameters
var parameters = rptObj.PluginInterface("").ReportParameters;
var count = parameters.count;
// iterate through parameters collection
for (var i = 1; i <= count; i++){
//get the parameter, its name and create a new parameter object
var prompti = parameters.item(i);
var paramName = prompti.ParameterName;
var newParam = Server.CreateObject("CrystalReports.ParameterField");
var discreteValue = Server.CreateObject("CrystalReports.ParameterFieldDiscreteValue");
var rangeValue = Server.CreateObject("CrystalReports.ParameterFieldRangeValue");
// get the value passed from the form via the parameter name
var strValue = String(Request.Form(paramName));
strValue = processDate(strValue);
Response.Write("<br>" + paramName);
Response.Write("----" + strValue);
// now run through the other parameters entered, start with range and then discrete parameters
if (prompti.SupportsRangeValues){
var beginRange = strValue.substr(1,strValue.indexOf("-") -1);
var endRange = strValue.substring(strValue.indexOf("-") + 1, strValue.length - 1)
rangeValue.lowerBoundType = 2;
rangeValue.upperBoundType = 2;
if (prompti.valueType <= 1){
rangeValue.beginValue = Number(beginRange);
rangeValue.endValue = Number(endRange);
newParam.Name = paramName;
}
else if (prompti.valueType >= 2 && prompti.valueType <= 5){
rangeValue.beginValue = makeDate(beginRange);
rangeValue.endValue = makeDate(endRange);
newParam.Name = paramName;
}
else {
rangeValue.beginValue = String(beginRange);
rangeValue.endValue = String(endRange);
newParam.Name = paramName;
}
}
else {
if (prompti.valueType <= 1){
discreteValue.value = Number(strValue);
newParam.Name = paramName;
}
else if (prompti.valueType >= 2 && prompti.valueType <= 5){
discreteValue.value = Date(strValue);
newParam.Name = paramName;
}
else {
discreteValue.value = String(strValue);
newParam.Name = paramName;
}
}
// be sure to set the secuirty and mpsURL parameters AFTER the other ones have been set
if(paramName == "viewer_role"){
discreteValue.value = Number(viewer_role);
newParam.Name = paramName;
}
if(paramName == "viewer_id"){
discreteValue.value = Number(viewer_id);
newParam.Name = paramName;
}
if(paramName == "mpsURL"){
discreteValue.value = String(mpsURL);
newParam.Name = paramName;
}
// Add the value to the param and then the param to the list
if (prompti.SupportsRangeValues){
newParam.currentValues.add(rangeValue);
Response.Write(" -- " + newParam.currentValues.item(0).value);
}
else
newParam.currentValues.add(discreteValue);
// update the fields collection with the new parameter
fields.add(newParam);
}
Response.Write("<br><br><br><table>");
for(var i=0; i < fields.count; i++) {
Response.Write("<tr><td width='40%'>" + i + " " + fields.item(i).name + "<td>");
Response.Write("<td>" + fields.item(i).currentValues.item(0).value + "</td>");
Response.Write("<td>" + fields.item(i).currentValues.count + "</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
return fields;
}