Solved

How to pass more than one parameter to crystal reports from Java?

Posted on 2008-10-03
1
1,128 Views
Last Modified: 2013-12-29
I have a JSP that can call a crystal report. This report requires one parameter. See the attached code snippet. Currently this code works fine and can display the report properly. But now I have modified the report to take in 2 parameters. So now I've added the following code after "numberParamField.setCurrentValues(numberValues);"

// logonUserId
String logonUserId = "5"
Integer numberValue2 = new Integer(logonUserId);
ParameterFieldDiscreteValue numParameterFieldDiscreteValue2 = new ParameterFieldDiscreteValue();
numParameterFieldDiscreteValue2.setValue(numberValue2);
Values numberValues2 = new Values();
numberValues2.add(numParameterFieldDiscreteValue2);
ParameterField numberParamField2 = new ParameterField();
numberParamField2.setName("logonUserId");
numberParamField2.setCurrentValues(numberValues2);

And after "parameterFields.add(numberParamField);" I added:

parameterFields.add(numberParamField2);

When I ran the JSP I get a "Some parameters are missing values" error message. How do I pass more than one parameter to the crystal report from Java?

Java Reporting Component API Reference:
http://devlibrary.businessobjects.com/BusinessObjectsXI/en/en/JRC_SDK/jrc_java_api_doc/doc/jrcsdk_java_apiRef/index.html
<%@ page import="com.crystaldecisions.report.web.viewer.*" %>
<%@ page import="com.crystaldecisions.report.web.viewer.CrystalReportViewer" %>
<%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory" %>
<%@ page import="com.crystaldecisions.reports.sdk.ReportClientDocument" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.*" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ConnectionInfo" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ConnectionInfos" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.Fields" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.IConnectionInfo" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ParameterField" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ParameterFieldDiscreteValue" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.Values" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSource" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2" %>
<%
//String report = request.getParameter("reportName") + ".rpt";
String report = "web/pages/report/CrystalReport1.rpt";
String matchId = request.getParameter("matchId");
IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();
IReportSource reportSource = (IReportSource)
rptSrcFactory.createReportSource(report, request.getLocale());
ConnectionInfos connInfos = new ConnectionInfos();
IConnectionInfo connInfo1 = new ConnectionInfo();
connInfo1.setUserName("sa");
connInfo1.setPassword("12qwaszx");
connInfos.add(connInfo1);
CrystalReportViewer viewer = new CrystalReportViewer();
viewer.refresh();
viewer.setReportSource(reportSource);
 
// matchId 
Integer numberValue = new Integer(matchId);
ParameterFieldDiscreteValue numParameterFieldDiscreteValue = new ParameterFieldDiscreteValue();
numParameterFieldDiscreteValue.setValue(numberValue);
Values numberValues = new Values();
numberValues.add(numParameterFieldDiscreteValue);
ParameterField numberParamField = new ParameterField();
numberParamField.setName("matchId");
numberParamField.setCurrentValues(numberValues);
 
Fields parameterFields = new Fields();
parameterFields.add(numberParamField);
viewer.setEnableParameterPrompt(false);
viewer.setParameterFields(parameterFields);
viewer.setDatabaseLogonInfos(connInfos);
viewer.setEnableLogonPrompt(false);
viewer.processHttpRequest(request, response,
getServletConfig().getServletContext(), out);
viewer.dispose();
%>

Open in new window

0
Comment
Question by:killdurst
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 22636538
Here are some sample programs to call reports.
There is one that shows how to pass several parameters

https://smpdl.sap-ag.de/~sapidp/012002523100006008962008E/crxi_jrc_jsp_smpl.zip

mlmcc
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
shared number array to be used in subreport 8 36
Problem to Alipay 10 72
Java basic valueOf question 1 34
Java array 10 63
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question