MicroStrategy ONE

Answering an Object Prompt

This example adds an object to the answer of an object prompt and submits the answer to Intelligence Server.

This code sample assumes that the values for message ID, state ID, prompt index, and prompt answer are obtained from the HTML form data.

// obtain the WebObjectSource and WebReportSource interfaces from the WebObjectsFactory

WebObjectsFactory factory = WebObjectsFactory.getInstance();

WebObjectSource objectSource = factory.getObjectSource();

WebReportSource reportSource = factory.getReportSource();

 

// get the messageID, stateID, prompt index, and prompt answer that are obtained from the HTML form data

String messageID = "";

int stateID = 1;

int pin = 1;

String promptAnswer = "";

 

// has the objectID for the object that has to be added to the answer list for the object prompt

String objectID = ""; // This is the object to be added to the object prompts answer list.

int objectType = 12;

 

try {

   // obtain the report instance

   WebReportInstance reportInstance = reportSource.getInstance(messageID, stateID);

 

   // check for prompted and non-prompted reports

   WebPrompt prompt = reportInstance.getPrompts().findPromptByPIN(pin);

   if(prompt == null) {

      Log.logger.log(Level.ERROR, "Unable to find the specified prompt instance!");

      return;

   }

 

   // load the existing answer XML

   prompt.populateAnswer(promptAnswer);

 

   if(prompt.getType() == EnumWebPromptType.WebPromptTypeObjects) {

      // get the object to add

      WebObjectInfo object = objectSource.getObject(objectID, objectType);

 

      // get the specific prompt interface

      WebObjectsPrompt objPrompt = (WebObjectsPrompt) prompt;

 

      // add the object to the existing collection

      objPrompt.getAnswer().add(object);

 

      // validate the answer before sending it to Intelligence Server

      objPrompt.validate();

 

      // answer the prompt and submits the answer to Intelligence Server

      objPrompt.answerPrompt();

   }

 

   else {

      Log.logger.log(Level.ERROR, "This not an object prompt!");

      return;

   }

}

 

catch (WebObjectsException e) {

   Log.logger.log(Level.ERROR, e.getMessage());

}

If additional prompts exist, such as in the case of embedded prompts where one prompt answer in turn forces another prompt to be answered, it is necessary to ensure the report instance is ready to accept answers for a prompt. As the answering of a prompt and subsequent Intelligence Server execution is asynchronous, it is necessary to poll the report instance to inquire its current state. After submitting a prompt answer, the very first status is likely to be executing until it discovers another prompt when the prompt status switches back to waiting for prompts. Before answering additional prompts, the application therefore needs to call pollStatus() on the ReportInstance. The value is a value of EnumDSSXMLStatus and must equal DssXmlStatusPromptXML before attempting to load a prompt. Whenever possible, it is best for prompts to be answered all at once rather than one by one.