Link to home
Start Free TrialLog in
Avatar of chompzilla
chompzillaFlag for United States of America

asked on

Pass Parameter Value to Crystal Report Subreport

I am using the CrystalReportViewers12 in my Apache Tomcat web-application. I have got the report to be fully functional and am even able to pass parameters to the Report. But when attempting to pass a parameter value to the sub-report I receive the following error:

ReportSDKParameterFieldException: Some parameters are missing values---- Error code:-2147217394 Error code name:missingParameterValueError.

I should mention that the parameter in the Sub-Report is linked to a field on the Main Report.

Here are the two methods I attempted to utilize to set the sub-report parameter value but to no avail.

//I know this method works for adding Parameter values to the main report
1. Fields parameterFields = new Fields();
ParameterField paramField = new ParameterField();
ParameterFieldDiscreteValue paramFieldDiscreteValue = new ParameterFieldDiscreteValue();
Values paramValues = new Values();

paramFieldDiscreteValue.setValue("PARAM_VALUE");
paramValues.add(paramFieldDiscreteValue);
paramField.setName("P_PARAMETER_NAME");
paramField.setCurrentValues(paramValues);
parameterFields.add(paramField);
parameterFields.setReportName("SUB_REPORT_NAME");
viewer.setParameterFields(parameterFields);


2. ReportClientDocument clientDoc  = new ReportClientDocument();
clientDoc.setReportAppServer(ReportClientDocument.inprocConnectionString);  
clientDoc.open("REPORT_NAME", OpenReportOptions._openAsReadOnly);

IStrings subNames = clientDoc.getSubreportController ().getSubreportNames ();
for (int subNum = 0; subNum < subNames.size (); subNum++)
{
    DataDefController dataDefController = clientDoc.getSubreportController().getSubreport(subNames.getString(subNum)).getDataDefController();

Fields paramFieldd = (Fields) dataDefController.getDataDefinition().getParameterFields();

    clientDoc.getDataDefController().getParameterFieldController().setCurrentValue(subNames.getString(subNum),paramFieldd.getField(subNum).getName(), 0);
}

At this point I'm a bit stuck and would appreciate any help.

Thanks.
Avatar of Mike McCracken
Mike McCracken

If you are linking on the parameter, you shouldn't have to pass the value to the subreport from the application.

mlmcc
Avatar of chompzilla

ASKER

I am linking on the parameter. I assumed as well that if I was linking on the parameter that I wouldn't be required to pass a value. I'm assuming I receive this error because I'm using the Viewer? If I remove the subreport, I can call/display the report just fine. This is why I'm at such a loss, because logically I shouldn't have to pass a value but apparently the viewer feels otherwise.
Does your dataset require login info? The missing parameter may be the logon info.
Are you setting your parameters AFTER you set your datasource?
If you try to set the parameters before you set your datasource the parameters get lost.
The dataset does require login info but that portion is functioning correctly. I have params in the main and subreport and if I remove params from subreport it will run correctly. As stated above I've attempted to replace the subreport param two diff ways with neither working.
When you remove params the subreport doesn't run then or it does and brings in everything?
Are you passing the login info to the subreport?
Try something like this:
Private Sub _setCRLogonInfo(ByRef report As ReportDocument)
  Dim connection As IConnectionInfo   Dim dbConnection As BaseClasses.Configuration.DatabaseConnection
  Dim connName As String = BOND_LOGTable.Instance.ConnectionName
   dbConnection = _
    DatabaseConnection.Parse(connName, _
    System.Configuration.ConfigurationManager.AppSettings("MyConnectionString"))
   ' Set Database Logon to main report
  For Each connection In report.DataSourceConnections
    connection.SetConnection(dbConnection.DatabaseServer, dbConnection.DatabaseName, False)
    connection.SetLogon(dbConnection.UserName, dbConnection.Password)
    'Do this twice for emphesis.  For some reason, doesn't seem to stick the 1st time.
    'connection.SetLogon(dbConnection.UserName, dbConnection.Password)
  Next
   ' Set Database Logon to subreport
  Dim subreport As ReportDocument
  For Each subreport In report.Subreports
    For Each connection In subreport.DataSourceConnections
      connection.SetConnection(dbConnection.DatabaseServer, dbConnection.DatabaseName, False)
      connection.SetLogon(dbConnection.UserName, dbConnection.Password)
    Next
  Next
End Sub
ASKER CERTIFIED SOLUTION
Avatar of chompzilla
chompzilla
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial