MicroStrategy ONE

Typical Processing of Prompts

This example demonstrates how to find the first open, used, and supported prompt. If no answer is specified for the prompt, either set the default or the previous answer as the answer to the prompt. In case of certain prompt types, the number of answers displayed is restricted. Obtain the Display XML for the prompt, and save the message ID, state ID, prompt index, and prompt answer.

// obtain the WebObjectSource and WebReportSource interfaces from the WebObjectsFactory

WebObjectsFactory factory = WebObjectsFactory.getInstance();

WebObjectSource objectSource = factory.getObjectSource();

WebReportSource reportSource = factory.getReportSource();

 

// specify the report to use

String reportID = "8D679D4211D3E4981000E787EC6DE8A4";

 

// specify the maximum number answers that are displayed at any given time

int maxObjects = 25;

 

try {

   // execute the report and obtain the report instance

   WebReportInstance reportInstance = reportSource.getNewInstance(reportID);

 

   // Check the status of the report instance

   int status = reportInstance.pollStatus();

 

   // check for prompted and non-prompted reports

   if(status != EnumDSSXMLStatus.DssXmlStatusPromptXML) {

      Log.logger.log(Level.ERROR, "This is not a prompted report!");

      return;

   }

 

   // Obtain the prompts collection

   WebPrompts prompts = reportInstance.getPrompts();

   WebPrompt prompt = null;

 

   // search for the first open, used, and supported prompt

   for(int i = 0; i < prompts.size(); i++) {

      prompt = prompts.get(i);

      if(prompt.isUsed() && !prompt.isClosed() && (prompt.getType() != EnumWebPromptType.WebPromptTypeUnsupported))

      break;

      prompt = null;

   }

 

   // If there is no open and used prompt, return

   if(prompt == null) {

      Log.logger.log(Level.ERROR, "There are no prompts that are open, used and supported in this collection.!");

      return;

   }

 

   // get the prompt type, and check if the prompt had an original, default, or previous answer,

   // or if no answer was specified. Once this information is retrieved, set the maximum number

   // of answers for display at any given time. This value is obtained from the maxObjects variable

   switch (prompt.getType()) {

 

      case EnumWebPromptType.WebPromptTypeObjects:

         WebObjectsPrompt objPrompt = (WebObjectsPrompt) prompt;

 

         // Check if the prompt did not come with an answer

         if(!objPrompt.hasOriginalAnswer()) {

 

            // Check if the prompt has a default answer

            if(objPrompt.hasDefaultAnswer()) {

               // Use default as answer

               objPrompt.setAnswer(objPrompt.getDefaultAnswer());                

            }

 

            // Check if the prompt has a previous answer

            else if(objPrompt.hasPreviousAnswer()) {

               // Use previous as answer

               objPrompt.setAnswer(objPrompt.getPreviousAnswer());

            }

         }

 

         if(objPrompt.getSearchRestriction() != null) {

            objPrompt.getSearchRestriction().setBlockBegin(1);

            objPrompt.getSearchRestriction().setBlockCount(maxObjects);

         }

      break;

 

      case EnumWebPromptType.WebPromptTypeElements:

         WebElementsPrompt elemPrompt = (WebElementsPrompt) prompt;

         elemPrompt.setBlockBegin(1);

         elemPrompt.setBlockCount(maxObjects);

      break;

 

      case EnumWebPromptType.WebPromptTypeExpression:

         WebExpressionPrompt expPrompt = (WebExpressionPrompt) prompt;

         if(expPrompt.getOrigin() != null && expPrompt.getOrigin().getType() == EnumDSSXMLObjectTypes.DssXmlTypeSearch) {

            ((WebSearch) expPrompt.getOrigin()).setBlockBegin(1);

            ((WebSearch) expPrompt.getOrigin()).setBlockCount(maxObjects);

         }

      break;

 

      case EnumWebPromptType.WebPromptTypeDimty:

         WebDimtyPrompt dmyPrompt = (WebDimtyPrompt) prompt;

         if(dmyPrompt.getSearchRestriction() != null) {

            dmyPrompt.getSearchRestriction().setBlockBegin(1);

            dmyPrompt.getSearchRestriction().setBlockCount(maxObjects);

         }

      break;

 

      default:

      break;

   }

 

   // retrieve the displayHelper object

   WebDisplayHelper displayHelper = prompt.getDisplayHelper();

   WebDefaultDisplaySettings defaultSettings = displayHelper.getDefaultDisplaySettings();

 

   // enable default highlighting

   defaultSettings.setUseDefaultHighlighting(true);

   defaultSettings.setUseDetailedHighlighting(true);

   defaultSettings.setUseDefaultSelection(true);

   // Note that the default element source is used only if the default highlighting algorithm

   // highlights an attribute. It is used only for expression prompts. For element prompts,

   // the attribute is marked highlighted with details and hence is not affected by the default

   // highlighting algorithm.

 

   // obtain the default element source and specify the maximum number of elements

   WebElementSource elemSrc = defaultSettings.getElementSource();

   elemSrc.setBlockBegin(1);

   elemSrc.setBlockCount(maxObjects);

 

   // save the messageID, stateID, prompt index, and prompt answer in HTML forms

   String messageID = reportInstance.getMessageID();

   int stateID = reportInstance.getStateID();

   int pin = prompt.getPIN();

   // Encoded for HTML use

   String promptAnswer = prompt.getAnswerXML(true);

 

}

 

catch (WebObjectsException e) {

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

}