SAP Knowledge Base Article - Public

1517547 - How to set the record selection formula using the Report Application Server SDK for .NET

Symptom

Resolution

  • Use the RecordFilterController:
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument = null;
 
boReportDocument.Load(Server.MapPath("Product Catalog.rpt"));
boReportClientDocument = boReportDocument.ReportClientDocument;
 
CrystalDecisions.ReportAppServer.Controllers.DataDefController boDataDefController = boReportClientDocument.DataDefController;
CrystalDecisions.ReportAppServer.Controllers.FilterController boRecordFilterController = boDataDefController.RecordFilterController;
 
CrystalDecisions.ReportAppServer.DataDefModel.FieldRangeFilterItem boFieldRangeFilterItem = new CrystalDecisions.ReportAppServer.DataDefModel.FieldRangeFilterItem();
CrystalDecisions.ReportAppServer.DataDefModel.OperatorFilterItem boOperatorFilterItem = new CrystalDecisions.ReportAppServer.DataDefModel.OperatorFilterItem();
 
// Find the field we want to filter on.
CrystalDecisions.ReportAppServer.DataDefModel.ISCRField boField = boDataDefController.FindFieldByFormulaForm("{Product.Product Name}");
       
// The value used in this case must be an ExpressionValue. It allows you to specify a formula, as well as a parameter field.
// Don't use the ConstantValue when specifying a parameter field. It won't work.
CrystalDecisions.ReportAppServer.DataDefModel.ExpressionValue boExpressionValue = new CrystalDecisions.ReportAppServer.DataDefModel.ExpressionValue();
boExpressionValue.Expression = "{?product}";
 
boFieldRangeFilterItem.RangeField = boField;
boFieldRangeFilterItem.Operation = CrystalDecisions.ReportAppServer.DataDefModel.CrSelectionOperationEnum.crSelectionOperationEqual;       
boFieldRangeFilterItem.Values.Add(boExpressionValue);
boRecordFilterController.AddItem(-1, boFieldRangeFilterItem);
       
// The parameter values MUST be set after you've configured your RecordFilter.
CrystalDecisions.ReportAppServer.Controllers.ParameterFieldController boParameterFieldController = boDataDefController.ParameterFieldController;
boParameterFieldController.SetCurrentValue("", "product", "Endorphin");
 
// do the rest of your code - preview, export or print.
  • An alternative method is to "manually" write the record selection formula:
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument = null;
 
boReportDocument.Load(Server.MapPath("Product Catalog.rpt"));
boReportClientDocument = boReportDocument.ReportClientDocument;
       
// This method allows you to write the record filter manually.
boReportClientDocument.DataDefinition.RecordFilter.FreeEditingText = "{Product.Product Name} = {?product}";
 
// The parameter values MUST be set after you've configured your RecordFilter.
CrystalDecisions.ReportAppServer.Controllers.ParameterFieldController boParameterFieldController = boReportClientDocument.DataDefController.ParameterFieldController;
boParameterFieldController.SetCurrentValue("", "product", "Endorphin");
 boReportClientDocument.DataDefController.RecordFilterController.Modify(filter)
 
// do the rest of your code - preview, export or print.

Keywords

KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2