How To Passing Parameter to Subreport in Crystal Reports XI

I have one .rpt which I created from a blank reports in Crystal Reports XI. The main report is just a simple select query that can prompt 1 parameter, the subreport is the member of one of the query's column (in this case i want to create a subreport for each department's employee detail).

The problem is, the subreport must receive another 2 parameter that doesn't linked to the main report at all. I've tried a normal way to receive the parameter one by one, but i get an error:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

I know that this is because the report (.rpt) just want to receive only 1 parameter from the main report because it only need 1 parameter in the main report query.

Here is my method to assign parameter (i use it in a jsp scriplet):

/**
 * Modify the crystal report document current value parameters.
 *
 * @param paramIndex the index position of the parameter.
 * @param valContent the value content for the parameter.
 * @param clientDoc the ReportClientDocument object.
 */
public void setDocParameter(int paramIndex, String valContent, ReportClientDocument clientDoc)
   throws ReportSDKException {
ParameterField newParameterField = null;
ParameterFieldDiscreteValue newDiscreteValue = null;

// Get the copy of the param object.
newParameterField = new ParameterField();
((ParameterField)clientDoc.getDataDefinition().getParameterFields().getField(paramIndex)).copyTo(
    newParameterField, true);

System.out.println(paramIndex);
// Set Discrete value.
newDiscreteValue = new ParameterFieldDiscreteValue();
newDiscreteValue.setValue(valContent);

// Set ParameterField with the Discrete value.
newParameterField.getCurrentValues().add(newDiscreteValue);

    // Modify with the new ParameterField
clientDoc.getDataDefController().getParameterFieldController().modify(
        (IParameterField)      clientDoc.getDataDefinition().getParameterFields().getField(paramIndex)
        , newParameterField);
}

It all works well to pass multiple values to the main report query, but when I want to pass it to the subreport query, it didn't work and shown the array index out of bound (because it didn't recognize that the subreport needs some values too)

Can someone help me in what way is the best practice to do what i wanna do? I can do it in a simple way, by using group by, not using subreport, but i want to try the subreport first. Sorry for my bad ways of questioning, I'm just a code noobs. Thank you.

Answers


I suggest still passing the parameter from the main report, even though it is not really coming from there. Just create 2 new parameters on the main report, then pass the parameters from the main report to the sub report. And use code the same way to get the values from c# into the crystal object.


Need Your Help

Get response from FlightStats SchedulesConnectionsService

xml api

I have included FlightStats SchedulesConnectionsService.wsdl as web refrence in my .Net application but don't know hot to get response from web service as XML

Angular-deckgrid and bindonce

javascript angularjs angularjs-directive angularjs-ng-repeat

Is there a way of using angular-bindonce together with angular-deckgrid, without making a custom changes to both plugins.