Cognos v11 SDK Parameter Passing

[亡魂溺海] 提交于 2020-05-17 06:45:26

问题


I have a webpage where the users can pick (n) records to print. Is there a way to send an array of Id's to Cognos?

Or is it better to save them off in a table or xml file and have cognos use that as a datasource?


回答1:


So you just create multiple simpleParmValueItems

parameterValue[] parameters = new parameterValue[1];
parameters[0] = new parameterValue();
parameters[0].name = "variableName";

parmValueItem[] pvi = new parmValueItem[2];
simpleParmValueItem item = new simpleParmValueItem();
item.use = "value1";
pvi[0] = item;
item = new simpleParmValueItem();
item.use = "value2";
pvi[1] = item;

parameters[0].value = pvi;



回答2:


Here is how I resolved it.

public AsynchReply runReport(final String reportSearchPath, final String format,
        final String param) {

    AsynchReply response;

    BaseParameter params[] = new Parameter[] {};
    final ParameterValue[] parameters = new ParameterValue[1];

    final SearchPathSingleObject reportPathObj = new SearchPathSingleObject();
    reportPathObj.set_value(reportSearchPath);
    try {
        // Get the report parameters name.
        response = this.getReportService().getParameters(reportPathObj, new ParameterValue[] {},
                new Option[] {});
        // If response is not immediately complete, call wait until complete
        if (!response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete)) {
            while (!response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete)) {
                response = this.getReportService().wait(response.getPrimaryRequest(),
                        new ParameterValue[] {}, new Option[] {});
            }
        }

        for (int i = 0; i < response.getDetails().length; i++) {
            if (response.getDetails()[i] instanceof AsynchDetailParameters) {
                params = ((AsynchDetailParameters) response.getDetails()[i]).getParameters();
            }
        }

        final SimpleParmValueItem item = new SimpleParmValueItem();
        item.setUse(param); // hard coded value for the parameter.
        item.setDisplay(param);
        item.setInclusive(true);

        final ParmValueItem[] paramValueItem = new ParmValueItem[1];
        paramValueItem[0] = item;
        parameters[0] = new ParameterValue();
        parameters[0].setName(params[0].getName());
        parameters[0].setValue(paramValueItem);

        final Option[] runOptions = new Option[4];

        final RunOptionBoolean saveOutput = new RunOptionBoolean();
        saveOutput.setName(RunOptionEnum.saveOutput);
        saveOutput.setValue(false);
        runOptions[0] = saveOutput;

        // Specify the output format.
        final RunOptionStringArray outputFormat = new RunOptionStringArray();
        outputFormat.setName(RunOptionEnum.outputFormat);
        outputFormat.setValue(new String[] {format});
        runOptions[1] = outputFormat;

        // Set the report not to prompt as we pass the parameters if any
        final RunOptionBoolean rop = new RunOptionBoolean();
        rop.setName(RunOptionEnum.prompt);
        rop.setValue(false);
        runOptions[2] = rop;

        final RunOptionInt maxRows = new RunOptionInt();
        maxRows.setName(RunOptionEnum.verticalElements);
        maxRows.setValue(0);
        runOptions[3] = maxRows;

        // Run the report
        response = this.getReportService().run(reportPathObj, parameters, runOptions);

        // If response is not immediately complete, call wait until complete
        if (!response.getStatus().equals(AsynchReplyStatusEnum.complete)
                && !response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete)) {
            while (!response.getStatus().equals(AsynchReplyStatusEnum.complete) && !response
                    .getStatus().equals(AsynchReplyStatusEnum.conversationComplete)) {
                // before calling wait, double check that it is okay
                if (ExecuteReportService.hasSecondaryRequest(response, "wait")) {
                    response = this.getReportService().wait(response.getPrimaryRequest(),
                            new ParameterValue[] {}, new Option[] {});
                } else {
                    System.out.println("Error: Wait method not available as expected.");
                    return null;
                }
            }
            // check if output is ready
            int i;
            for (i = 0; i < response.getDetails().length; i++) {
                if ((response.getDetails()[i] instanceof AsynchDetailReportStatus)
                        && (((AsynchDetailReportStatus) response.getDetails()[i])
                                .getStatus() == AsynchDetailReportStatusEnum.responseReady)
                        && (this.hasSecondaryRequest(response, "getOutput"))) {
                    response = this.getReportService().getOutput(response.getPrimaryRequest(),
                            new ParameterValue[] {}, new Option[] {});
                    break;
                }
            }
            // if output is not ready return to main
            if (i == 3) {
                System.out.println("Output was not generated");
                return null;
            }
        }

        // release the conversation to free resources.
        if (ExecuteReportService.hasSecondaryRequest(response, "release")) {
            // System.out.println("Releasing resources");
            this.getReportService().release(response.getPrimaryRequest());
        }
        return response;

    } catch (final Exception ex) {
        System.out.println(ex);
        ex.printStackTrace();
    }

    return null;
}


来源:https://stackoverflow.com/questions/52210133/cognos-v11-sdk-parameter-passing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!