Cognos v11 SDK 参数传递
Cognos v11 SDK Parameter Passing
我有一个网页,用户可以在其中选择 (n) 条记录进行打印。有没有办法将一组 ID 发送到 Cognos?
还是将它们保存在 table 或 xml 文件中并让 cognos 将其用作数据源更好?
因此您只需创建多个 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;
我是这样解决的。
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;
}
我有一个网页,用户可以在其中选择 (n) 条记录进行打印。有没有办法将一组 ID 发送到 Cognos?
还是将它们保存在 table 或 xml 文件中并让 cognos 将其用作数据源更好?
因此您只需创建多个 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;
我是这样解决的。
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;
}