SUMMARY: This Technical Note explains how a user can develop an add-on for the report page that will collect the prompt answer XML for a nested prompt from a report and use it to answer the same prompt on another report using Strategy Web SDK 9.4.x.
The following code demonstrates how to build an add-on with this functionality:
private static String answerXML = null;
public String getAddOnDescription() {
return "";
}
public void preCollectData(PageComponent page) {
System.out.println("Pre-collect");
ReportBean rb = (ReportBean) page.getChildByClass(ReportBean.class);
if(answerXML == null || !rb.getObjectID().equals("Report ID") return;
System.out.println("XML Precollect:" + answerXML +"\n");
try {
rb.collectData();
while (rb.getXMLStatus() == EnumRequestStatus.WebBeanRequestWaitingForUserInput)
answerPromptsUsingAnswerXML(answerXML, rb);
} catch (WebBeanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void postCollectData(PageComponent page) {
ReportBean rb = (ReportBean) page.getChildByClass(ReportBean.class);
System.out.println("Post-collect");
if(!rb.getObjectID().equals("Report ID")) return;
int status;
try {
rb.collectData();
status = rb.getResultSetInstance().pollStatus();
if (status == EnumDSSXMLStatus.DssXmlStatusResult) {
WebPrompts prompts = rb.getPromptsBean().getPrompts();
prompts.setClosed(false);
answerXML = prompts.getAnswerXML();
prompts.setClosed(true);
}
} catch (WebObjectsException e) {
e.printStackTrace();
} catch (WebBeanException e) {
e.printStackTrace();
} catch (WebReportValidationException e) {
e.printStackTrace();
}
}
private void answerPromptsUsingAnswerXML(ReportBean rb, String answerXML) {
try {
WebResultSetInstance instance = rb.getResultSetInstance();
int status = instance.pollStatus();
if (status == EnumDSSXMLStatus.DssXmlStatusPromptXML) {
WebPrompts prompts = rb.getResultSetInstance().getPrompts();
prompts.populateAnswers(answerXML);
prompts.validate();
prompts.answerPrompts();
rb.collectData();
}
} catch (Exception e) {
// TODO: handle exception
}
}