MicroStrategy ONE
Prompts Transform Example
In the following code sample, you see how a relatively simple Prompt Transform’s code might look. The main transform() method does the following things:
-
Instantiates the PromptsBean object from the request.
-
Creates an iterator and populates it with all open (or unanswered) prompts.
-
For each prompt in the iteration, establishes a PromptObject and calls the renderPrompt function that was created elsewhere in this transform.
The renderPrompt() function is presumed to be outside the main transform() function in this Transform. renderPrompt() does the following things:
-
Takes the PromptObject, determines what prompt it is in the collection (first, second, etc.); and writes it to the screen.
-
Derives a WebPrompt from the PromptObject.
-
In the event that this WebPrompt is of type WebPromptTypeConstant (in other words, a ‘constant prompt’ or ‘value prompt’):
-
It takes the current WebPrompt, casts it as a WebConstantPrompt, and gets the current answer. (In this case, since you have not provided an answer, you can assume the current answer is the default answer.)
-
Outputs the current answer to the screen.
-
-
If this prompt is not a constant prompt, indicate that it is not supported.
This is a simple example. In reality, this would only be half the process for completing report execution with prompts. The second half would involve calling answerPrompt() after providing an answer, and continuing with the report execution.
Code Sample
package mypackage.name;
import com.microstrategy.web.beans.*;
import com.microstrategy.web.objects.*;
import com.microstrategy.web.transform.*;
import com.microstrategy.webapi.*;
import java.io.*;
public class SimplePromptTransform extends AbstractTransform {
public String getDescription() {
return “This transform outputs to the screen the current prompt answer for a constant prompt”;
}
public void transform(Transformable parm1, MarkupOutput out) {
try {
PromptsBean pb = (PromptsBean)parm1;
Iterator i = pb.getPromptObjects( EnumPromptsBeanTypes.PromptsBeanTypeOpen);
while(i.hasNext()){
PromptObject po = (PromptObject)i.next();
renderPrompt(po,out);
}
catch (Exception e){
out.append("Execution ends in error " + e.getMessage());
}
}
public Class getSupportedBeanType() {
return PromptsBean.class;
}
}
private void renderPrompt(PromptObject po, MarkupOutput out) throws Exception {
int pos = po.getPromptPosition();
out.append("Rendering prompt at position " + pos + "\n");
WebPrompt wp = po.getWebPrompt();
switch (wp.getPromptType()){
case EnumWebPromptType.WebPromptTypeConstant:
String ans = ((WebConstantPrompt)wp).getAnswer();
out.append("The current answer is " + ans + "\n");
break;
default:
out.append("The prompt type " + wp.getPromptType() + " is not supporter \n");
}
}