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.
0
votes
3 Answers
2
votes
0
votes
I was doing some research about this and noticed that there are 3 methods with which you can do this:
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.
As Francisco said in his answer, using the
setFormulaText
method:clientDoc.getDataDefController().getRecordFilterController().setFormulaText("{Customer.Country} = 'Canada'");
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