SUMMARY: This Technical Note explains how a user can develop an add-on for the report page that will to programmatically pre-populate the prompt answers for a nested prompt that has an underlying report as a filter then retrieve the new prompt answer XML with Strategy Web SDK 9.4.x.
The following code demonstrates how to build an add-on with this functionality:
public void preCollectData(PageComponent page) {
System.out.println("Pre-collect");
String answerXML = "Your answer XML";
ReportBean rb = (ReportBean) page.getChildByClass(ReportBean.class);
try {
rb.collectData();
} catch (WebBeanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
answerPromptsUsingAnswerXML(rb, answerXML);
}
public void postCollectData(PageComponent page) {
ReportBean rb = (ReportBean) page.getChildByClass(ReportBean.class);
System.out.println("Post-collect");
int status;
try {
rb.collectData();
status = rb.getResultSetInstance().pollStatus();
if (status == EnumDSSXMLStatus.DssXmlStatusResult) {
WebPrompts prompts = rb.getPromptsBean().getPrompts();
prompts.setClosed(false);
rb.collectData();
String newAnswerXML = prompts.getShortAnswerXML();
prompts.setClosed(true);
rb.collectData();
System.out.println("New answer XML:" + newAnswerXML + "\n");
}
} 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 = instance.getPrompts();
prompts.populateAnswers(answerXML);
rb.collectData();
}
} catch (Exception e) {
// TODO: handle exception
}
}
try {
rb.collectData();
status = rb.getResultSetInstance().pollStatus();
if (status == EnumDSSXMLStatus.DssXmlStatusResult) {
WebReportInstance newInst = rb.getReportInstance().getReportManipulator().applyChanges();
newInst.setAsync(false);
int newstatus = newInst.pollStatus();
rb.collectData();
WebPrompts prompts = rb.getPromptsBean().getPrompts();
prompts.setClosed(false);
rb.getReportInstance().setAsync(false);
rb.getReportInstance().pollStatus();
rb.collectData();
String newAnswerXML = prompts.getShortAnswerXML();
prompts.setClosed(true);
rb.collectData();
System.out.println("New answer XML:" + newAnswerXML + "\n");
}
} catch (WebObjectsException e) {
e.printStackTrace();
} catch (WebBeanException e) {
e.printStackTrace();
} catch (WebReportValidationException e) {
e.printStackTrace();
}