Question

I have a Java application the invokes Crystal Reports through its Java libraries. One of the reports has the following clause in its record selector:

and ({DriverMotionView.GROUPID} = {?GroupID1Parameter}
or {DriverMotionView.GROUPID} = {?GroupID2Parameter}
or {DriverMotionView.GROUPID} = {?GroupID3Parameter}
or {DriverMotionView.GROUPID} = {?GroupID4Parameter}
or {DriverMotionView.GROUPID} = {?GroupID5Parameter}
or {DriverMotionView.GROUPID} = {?GroupID6Parameter}
or {DriverMotionView.GROUPID} = {?GroupID7Parameter}
or {DriverMotionView.GROUPID} = {?GroupID8Parameter}
or {DriverMotionView.GROUPID} = {?GroupID9Parameter}
or {DriverMotionView.GROUPID} = {?GroupID10Parameter}
)

Each GroupIDnParameter is an integer groupID, created by selecting a group names from a tree structure in the UI. The UI converts these to groupIDs and passes them into the report. Now this record selector works but limits the number of selected groups to 10.

I would like to remove this limit. To check the syntax of a possible solution, I first tried the following

and {DriverMotionView.GROUPID} in [-1, 1618, 1608, 1610, -1]

This does indeed select the records for groupIDs 1618, 1608 and 1610.

So then I tried things like

and {DriverMotionView.GROUPID} in {?GroupIDListParameter}

where the GroupIDListParameter is passed in as the string [-1, 1618, 1608, 1610, -1]. This results in a run time Crystal Reports error.

I tried

and {DriverMotionView.GROUPID} in [{?GroupIDListParameter}] 

but that clause is syntactically incorrect and results in a "array must be subscripted" error on a syntax check.

There is likely another approach to solving this problem, but I was not able to find it in the on-line help, reading the User's Guide or even Google searches.

Any suggestions would be appreciated.

Was it helpful?

Solution 3

Here's the answer. I replaced

and ({DriverMotionView.GROUPID} = {?GroupID1Parameter}
or {DriverMotionView.GROUPID} = {?GroupID2Parameter}
or {DriverMotionView.GROUPID} = {?GroupID3Parameter}
or {DriverMotionView.GROUPID} = {?GroupID4Parameter}
or {DriverMotionView.GROUPID} = {?GroupID5Parameter}
or {DriverMotionView.GROUPID} = {?GroupID6Parameter}
or {DriverMotionView.GROUPID} = {?GroupID7Parameter}
or {DriverMotionView.GROUPID} = {?GroupID8Parameter}
or {DriverMotionView.GROUPID} = {?GroupID9Parameter}
or {DriverMotionView.GROUPID} = {?GroupID10Parameter}
)

with

and ({DriverMotionView.GROUPID} in {?GroupIDArrayParameter})

Where the GroupIDArrayParameter is declared as a number parameter allowing discrete and multiple values. Custom values are allowed but I don't think that matters. What is key is that the type of the GroupIDArrayParameter (number) match the type of the DriverMotionView.GROUPID which is a number as well.

The code that sets the GroupIDArrayParameter is essentially as follows:

 Fields fields = new Fields ();
 ... //Set other parameters here
 setDiscreteArrayParameter(fields, "GroupIDArrayParameter", "",  
                           getIntGroupIDs(groups));

 ...

 // Convert String groupIDs to Integers
 private Integer[] getIntGroupIDs(String[] s) {
     Integer[] result = new Integer[s.length];
     for (int i = 0; i < s.length; i++) {
        result[i] = Integer.parseInt(s[i]);
     }
     return result;
}

...

private void setDiscreteArrayParameter(Fields fields, String paramName, 
                           String reportName, Object[] parameterValues) {
    logger.debug("DescreteParameter - Name: " + paramName);
    // Create parameter field
    ParameterField parmeterField = new ParameterField();
    // Set report name
    parmeterField.setReportName(reportName);
    // Set parameter name
    parmeterField.setName(paramName);
    // Create value     
    Values values = new Values();
    for (int i = 0; i < parameterValues.length; i++) {
        ParameterFieldDiscreteValue discreteValue = new ParameterFieldDiscreteValue();
        discreteValue.setValue(parameterValues[i]);
        values.add(discreteValue);
     }
 parmeterField.setCurrentValues(values);
     fields.add(parmeterField);
}

There may even be cleaner ways to do this, but I have only so much time to investigate.

Enjoy

OTHER TIPS

You said that the {?GroupIDListParameter} is passed in as a string which includes the brackets ([ ]) around the values. Did you type that in/do it with code? Whatever you are doing to get the brackets there, I would remove them and then try this around just the comma separated string of numebrs that are put in {?GroupIDListParameter}:

{DriverMotionView.GROUPID} in split({?GroupIDListParmeter},",")

You need to set your {?GroupIDListParameter} to be a multi-valued parameter (a property of the parameter itself). This will treat it as an array so you can do the record selection with a simple {DriverMotionView.GROUPID} in {?GroupIDListParameter} like you had already tried.

There is no need to delimit the values or use square-brackets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top