chompzilla
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:
ReportSDKParameterFieldExc eption: Some parameters are missing values---- Error code:-2147217394 Error code name:missingParameterValue Error.
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();
ParameterFieldDiscreteValu e paramFieldDiscreteValue = new ParameterFieldDiscreteValu e();
Values paramValues = new Values();
paramFieldDiscreteValue.se tValue("PA RAM_VALUE" );
paramValues.add(paramField DiscreteVa lue);
paramField.setName("P_PARA METER_NAME ");
paramField.setCurrentValue s(paramVal ues);
parameterFields.add(paramF ield);
parameterFields.setReportN ame("SUB_R EPORT_NAME ");
viewer.setParameterFields( parameterF ields);
2. ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServ er(ReportC lientDocum ent.inproc Connection String);
clientDoc.open("REPORT_NAM E", OpenReportOptions._openAsR eadOnly);
IStrings subNames = clientDoc.getSubreportCont roller ().getSubreportNames ();
for (int subNum = 0; subNum < subNames.size (); subNum++)
{
DataDefController dataDefController = clientDoc.getSubreportCont roller().g etSubrepor t(subNames .getString (subNum)). getDataDef Controller ();
Fields paramFieldd = (Fields) dataDefController.getDataD efinition( ).getParam eterFields ();
clientDoc.getDataDefContro ller().get ParameterF ieldContro ller().set CurrentVal ue(subName s.getStrin g(subNum), paramField d.getField (subNum).g etName(), 0);
}
At this point I'm a bit stuck and would appreciate any help.
Thanks.
ReportSDKParameterFieldExc
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();
ParameterFieldDiscreteValu
Values paramValues = new Values();
paramFieldDiscreteValue.se
paramValues.add(paramField
paramField.setName("P_PARA
paramField.setCurrentValue
parameterFields.add(paramF
parameterFields.setReportN
viewer.setParameterFields(
2. ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServ
clientDoc.open("REPORT_NAM
IStrings subNames = clientDoc.getSubreportCont
for (int subNum = 0; subNum < subNames.size (); subNum++)
{
DataDefController dataDefController = clientDoc.getSubreportCont
Fields paramFieldd = (Fields) dataDefController.getDataD
clientDoc.getDataDefContro
}
At this point I'm a bit stuck and would appreciate any help.
Thanks.
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.
If you try to set the parameters before you set your datasource the parameters get lost.
ASKER
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?
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. DatabaseCo nnection
Dim connName As String = BOND_LOGTable.Instance.Con nectionNam e
dbConnection = _
DatabaseConnection.Parse(c onnName, _
System.Configuration.Confi gurationMa nager.AppS ettings("M yConnectio nString"))
' Set Database Logon to main report
For Each connection In report.DataSourceConnectio ns
connection.SetConnection(d bConnectio n.Database Server, dbConnection.DatabaseName, False)
connection.SetLogon(dbConn ection.Use rName, dbConnection.Password)
'Do this twice for emphesis. For some reason, doesn't seem to stick the 1st time.
'connection.SetLogon(dbCon nection.Us erName, dbConnection.Password)
Next
' Set Database Logon to subreport
Dim subreport As ReportDocument
For Each subreport In report.Subreports
For Each connection In subreport.DataSourceConnec tions
connection.SetConnection(d bConnectio n.Database Server, dbConnection.DatabaseName, False)
connection.SetLogon(dbConn ection.Use rName, dbConnection.Password)
Next
Next
End Sub
Private Sub _setCRLogonInfo(ByRef report As ReportDocument)
Dim connection As IConnectionInfo Dim dbConnection As BaseClasses.Configuration.
Dim connName As String = BOND_LOGTable.Instance.Con
dbConnection = _
DatabaseConnection.Parse(c
System.Configuration.Confi
' Set Database Logon to main report
For Each connection In report.DataSourceConnectio
connection.SetConnection(d
connection.SetLogon(dbConn
'Do this twice for emphesis. For some reason, doesn't seem to stick the 1st time.
'connection.SetLogon(dbCon
Next
' Set Database Logon to subreport
Dim subreport As ReportDocument
For Each subreport In report.Subreports
For Each connection In subreport.DataSourceConnec
connection.SetConnection(d
connection.SetLogon(dbConn
Next
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mlmcc