Using the Strategy Java Web SDK 9.4.x, it is possible to answer prompts passing the answers in an XML format. The following code sample shows how this can be done by populating the prompts collection with the answer xml:
String strReportID = "2C825EA14436B7FFBAA94B960814EDEA";
String answerXML = "<rsl lcl=\"1033\"><pa pt=\"4\" pin=\"0\" did=\"98EE6D294C3B1F5157214B954C50DA48\" tp=\"10\">2007</pa><pa pt=\"7\" pin=\"0\" did=\"6144DFEA4AC1D541B8FCEE9F2A720767\" tp=\"10\"><mi><es dirty=\"1\"><at did=\"8D679D4F11D3E4981000E787EC6DE8A4\" tp=\"12\" stp=\"3072\" n=\"Subcategory\" disp_n=\"Subcategory\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:23\" emt=\"1\" art=\"1\" disp_n=\"Computers\" disp_id=\"1\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:25\" emt=\"1\" art=\"1\" disp_n=\"TV's\" disp_id=\"2\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:31\" emt=\"1\" art=\"1\" disp_n=\"Action\" disp_id=\"3\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:26\" emt=\"1\" art=\"1\" disp_n=\"Video Equipment\" disp_id=\"4\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:46\" emt=\"1\" art=\"1\" disp_n=\"Soul / R&B\" disp_id=\"5\"/></es></mi></pa></rsl>";
WebReportSource reportSource=factory.getReportSource();
WebReportInstance reportInstance=null;
//The user gets an instance of the report but the prompts have not yet been answered
reportInstance=reportSource.getNewInstance(strReportID);
reportInstance.setAsync(false);
reportInstance.setMaxWait(120000);
reportInstance.setPollingFrequency(250);
WebPrompts oPrompts = null;
WebPrompt oPrompt = null;
int status = reportInstance.pollStatus();
if (status == EnumDSSXMLStatus.DssXmlStatusPromptXML){
//Get the prompts from the report
oPrompts = reportInstance.getPrompts();
//set the answer xml on the prompts collection
oPrompts.populateAnswers(answerXML);
oPrompts.validate();
oPrompts.answerPrompts();
}
//the report results are ready
WebReportData wrd = reportInstance.getResults();
However, it is possible to further optimize this process by eliminating the call to the Intelligence Server to first retrieve the prompts from the report before answering them. For example, looking at the above code snippet, the prompt answerXML is not being set until after the call to get the prompts collection if the report is in prompt status. The call to get the prompts collection requires a trip back to the Intelligence Server.
The following code shows how to optimize this process by setting the prompt answer XML on the WebReportSource object instead:
String strReportID = "2C825EA14436B7FFBAA94B960814EDEA";
String answerXML = "<rsl lcl=\"1033\"><pa pt=\"4\" pin=\"0\" did=\"98EE6D294C3B1F5157214B954C50DA48\" tp=\"10\">2007</pa><pa pt=\"7\" pin=\"0\" did=\"6144DFEA4AC1D541B8FCEE9F2A720767\" tp=\"10\"><mi><es dirty=\"1\"><at did=\"8D679D4F11D3E4981000E787EC6DE8A4\" tp=\"12\" stp=\"3072\" n=\"Subcategory\" disp_n=\"Subcategory\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:23\" emt=\"1\" art=\"1\" disp_n=\"Computers\" disp_id=\"1\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:25\" emt=\"1\" art=\"1\" disp_n=\"TV's\" disp_id=\"2\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:31\" emt=\"1\" art=\"1\" disp_n=\"Action\" disp_id=\"3\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:26\" emt=\"1\" art=\"1\" disp_n=\"Video Equipment\" disp_id=\"4\"/><e ei=\"8D679D4F11D3E4981000E787EC6DE8A4:46\" emt=\"1\" art=\"1\" disp_n=\"Soul / R&B\" disp_id=\"5\"/></es></mi></pa></rsl>";
WebReportSource reportSource=factory.getReportSource();
// prompt answer xml is set on the report source before getting the report instance
reportSource.setPromptAnswer(answerXML);
WebReportInstance reportInstance=null;
//the prompts have already been answered in this report instance
reportInstance=reportSource.getNewInstance(strReportID);
reportInstance.setAsync(false);
reportInstance.setMaxWait(120000);
reportInstance.setPollingFrequency(250);
int status = reportInstance.pollStatus();
//the results are ready without having to make a trip to the I-server to get the prompts
WebReportData wrd = reportInstance.getResults();
The WebReportSource object is responsible for executing reports and returning the report instance to the user. Notice that the WebReportSource object is being used in both code snippets, but the 2nd code snippet demonstrates how the prompt answer xml can be set on the WebReportSource so when the Report Instance is returned to the user, the prompts have already been answered, thus reducing the amount of calls made to the Intelligence Server.
Code Customization:
WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.