【问题标题】:Cognos v11 SDK Parameter PassingCognos v11 SDK 参数传递
【发布时间】:2020-04-30 19:54:47
【问题描述】:

我有一个网页,用户可以在其中选择 (n) 条记录进行打印。有没有办法将一组 ID 发送到 Cognos?

还是将它们保存在表格或 xml 文件中并让 cognos 将其用作数据源更好?

【问题讨论】:

    标签: c# sdk cognos


    【解决方案1】:

    所以你只需创建多个 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;
    

    【讨论】:

    • 欣赏这一点。我正在尝试遵循相同的方法。我当前的示例要简单得多 - 我只想传入一个参数。但是,当我运行它时,会呈现参数页面而不是基础报告。这是我的代码: ParameterValue parameters[] = new ParameterValue[1];参数[0] = new ParameterValue();参数[0].setName("pFundingDescription"); ParmValueItem[] pvi = 新的 ParmValueItem[1]; SimpleParmValueItem 项 = 新的 SimpleParmValueItem(); item.setUse("自动付款"); pvi[0] = 项目;参数[0].setValue(pvi);
    • aj,看起来是正确的。我不确定您是如何处理用户名/密码的,但我们也必须包括这些。
    • 只使用ibm提供的示例程序。密码不是问题,因为当报告中没有参数时,整个事情都可以正常工作。
    【解决方案2】:

    这是我解决它的方法。

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多