Modifying an existing filter formula

Existing filter formulas in a report can be modified two ways:
  • Use the setFormulaText method of the com.crystaldecisions.sdk.occa.report.application.FilterController class.
    public void modifyFilterText(ReportClientDocument rcd) throws ReportSDKException
    {
        DataDefController dataDefController = rcd.getDataDefController();
        FilterController recordFilterController = dataDefController.getRecordFilterController();
        recordFilterController.setFormulaText("{Customer.Country} = \"USA\" OR {Customer.Country} = \"Switzerland\"");
    }
    This method completely replaces the existing filter formula with the new string.
  • Clone the existing filter and modify the formula using the setFilterItems method.
    void modifyFilter(ReportClientDocument rcd) throws ReportSDKException
    {
      DataDefController dataDefController = rcd.getDataDefController();
      FilterController recordFilterController = dataDefController.getRecordFilterController();
      IFilter oldRecordFilter = dataDefController.getDataDefinition().getRecordFilter();
      Filter newRecordFilter = (Filter)oldRecordFilter.clone(true);
      FilterItems filterItems = newRecordFilter.getFilterItems();
    
      // Make changes to individual parts of the FilterItems collection
    
      recordFilterController.modify(newRecordFilter);
    }
    This method allows you to select and change the fields, values, and operators of the existing formula.

    Note: When the report is programmatically opened as a ReportClientDocument object, the formula is parsed into a FilterItems collection. However, if the formula is too complex to be parsed, the FilterItems collection remains empty and the string representation of the formula can be retrieved and set using the setFreeEditingText method of the IFilter interface instead.
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.DataDefController
  • com.crystaldecisions.sdk.occa.report.application.FilterController
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.data.IFilter
  • com.crystaldecisions.sdk.occa.report.data.Filter
  • com.crystaldecisions.sdk.occa.report.data.FilterItems
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException