MicroStrategy ONE
Capturing the Prompt Answers Supplied by the User at Runtime
The following code sample illustrates how to capture, in an XML format, the prompt answers that a user enters in at runtime. This XML can then be used to answer prompts programmatically.
package com.microstrategy.sdk.addons;
import com.microstrategy.web.app.addons.AbstractAppAddOn;
import com.microstrategy.web.app.beans.PageComponent;
import com.microstrategy.web.beans.EnumRequestStatus;
import com.microstrategy.web.beans.ReportBean;
import com.microstrategy.web.beans.WebBeanException;
import com.microstrategy.web.objects.WebObjectsException;
import com.microstrategy.web.objects.WebPrompts;
import com.microstrategy.web.objects.WebReportInstance;
public class GetAnswerXMLAddon extends AbstractAppAddOn {
public void postCollectData(PageComponent page) {
//Retrieve the Report Bean from the page
ReportBean rb = (ReportBean) page.getChildByClass(ReportBean.class);
if (rb == null) return;
try {
//Check to see if the report is the report needed
if (rb.getObjectID().equalsIgnoreCase("9CDB05884A0D22AEE1CFBAA837198D42")){
//Check to see if the report is successful (not waiting for user input or error)
if(rb.getXMLStatus()== EnumRequestStatus.WebBeanRequestSuccessful ){
WebReportInstance oInst = rb.getReportInstance();
//Retrieve the prompts
WebPrompts oPrompts = oInst.getPrompts();
oPrompts.setClosed(false);
//Print Answer XML
String answerXML = oPrompts.getShortAnswerXML();
System.out.println("Prompt Answer XML:" +answerXML);
String encodedAnswerXML = oPrompts.getShortAnswerXML(true);
System.out.println("Encoded Prompt Answer XML:"+ encodedAnswerXML);
oPrompts.setClosed(true);
}
}
}
catch (WebBeanException e) {
e.printStackTrace();
}
catch (WebObjectsException e) {
e.printStackTrace();
}
}
public String getAddOnDescription() {
return "Shows how to get the answerXML from prompts the user has answered";
}
}