To add a parameter field to a report

  1. Create a new parameter field.
    ParameterField parameterField = new ParameterField();
  2. Set the parameter field name, and description.
    parameterField.setName("MyParameter");
    parameterField.setDescription("Enter a value.");
  3. Set the type of parameter.

    Note: Not all types may be used for parameter fields. For example, you may not set Type to 20 (Bitmap). Use the isValidType method in the ParameterFieldController class to determine if a certain type is valid for a parameter field.
    parameterField.setValueRangeKind(ParameterValueRangeKind.discrete);
    parameterField.setParameterType(ParameterFieldType.queryParameter);
    parameterField.setType(FieldValueType.numberField);
  4. Set what values are allowed in the parameter field.
    parameterField.setAllowCustomCurrentValues(false);
    parameterField.setAllowMultiValue(false);
    parameterField.setAllowNullValue(false);
  5. Add the parameter to the report using the ParameterFieldController class.

    Note: When a parameter is added using the ParameterFieldController class, it is not placed on the report, and the user will not be prompted when the report is refreshed. To use the parameter field to prompt a user, the parameter must be used in a filter, or must be added using the ResultFieldController class.
    rcd.getDataDefController().getParameterFieldController().add(parameterField);
Example: 
The following example defines a new, discrete, number parameter and adds it using the ParameterFieldController:
void addParameter(ReportClientDocument rcd) throws ReportSDKException
{
   IParameterField parameterField = new ParameterField();
   parameterField.setName("MyParameter");
   parameterField.setDescription("Enter a value.");
   parameterField.setValueRangeKind(ParameterValueRangeKind.discrete);
   parameterField.setParameterType(ParameterFieldType.reportParameter); 
   parameterField.setType(FieldValueType.numberField);
       
   parameterField.setAllowMultiValue(false);
   parameterField.setAllowNullValue(false);
   rcd.getDataDefController().getParameterFieldController().add(parameterField);
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.data.FieldValueType
  • com.crystaldecisions.sdk.occa.report.data.ParameterField
  • com.crystaldecisions.sdk.occa.report.data.IParameterField
  • com.crystaldecisions.sdk.occa.report.data.ParameterValueRangeKind
  • com.crystaldecisions.sdk.occa.report.data.ParameterFieldType
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException