0
votes

How do you create/set Record Selection Formula programatically on crystal reports using java? I tried searching on the internet but the only option is through IFilter which requires a Crystal Report Server. My program only uses the JRC library. Also this is a java desktop application using swing.

3
what do you mean by "create/set Record Selection Formula programatically"? don't you use SQL to select your data?mostafa.S
A vote down to this question is really disappointing. :|John

3 Answers

2
votes

It may be a bit late, but maybe this is useful for someone:

reportClientDoc.getDataDefController().getRecordFilterController().setFormulaText("your record selection formula here");
0
votes

I was doing some research about this and noticed that there are 3 methods with which you can do this:

  1. Using the IFilter interface as shown in this example provided by SAP

    // Set the filter string to be used as the Record Filter
    String freeEditingFilter = "{Customer.Country} = 'Canada'";
    // Retrieve the record filter for the Data Definition Controller
    IFilter iFilter = clientDoc.getDataDefController().getDataDefinition().getRecordFilter();
    // Set the filter to free editing text filter string
    iFilter.setFreeEditingText(freeEditingFilter);
    // Modify the filter through the Record Filter Controller to the report
    clientDoc.getDataDefController().getRecordFilterController().modify(iFilter);
    

    I am using the JRC only without a Crystal Report Server and the above example worked for me.

  2. As Francisco said in his answer, using the setFormulaText method:

    clientDoc.getDataDefController().getRecordFilterController().setFormulaText("{Customer.Country} = 'Canada'");
    
  3. Using parameters. Parameters can be passed to the report using code (you can use the addDiscreteParameterValue function in the helper class) or else they can be filled in by the user during runtime. I chose not to opt for this option because they can not be set to optional

-2
votes

If you want to create a crystal report of your program, you need another jar file of software. You can create your program in NetBeans IDE and link your IDE with IReport software which is used in NetBeans for creating Reporting in java. You get many example from internet about this.