MicroStrategy ONE
Code Sample
The following code sample helps you understand the process of using a PromptsBean.
//This example uses a transform to render a prompt’s data
//Step 1. Create Report Bean, set State and I-Server session
// as done for instructions on using the ReportBean
rb.setObjectName("Prompt Report Example");
//Step 2. Get PromptsBean, and associate a TransformInstance that supports a PromptsBean
PromptsBean pb = rb.getPromptsBean();
TransformInstance ti1 = pb.addTransform(new com.microstrategy.web.app.transforms.PromptsClassicTransform());
ti1.setKey("prompt");
//Step 3. Call collectData() and render data – be sure to transform the PromptsBean to render the data returned by a prompt
rb.collectData();
MarkupOutput mo = pb.transform("prompt");
StringWriter sw = new StringWriter();
mo.send(sw);
out.println(sw.getBuffer().toString());
Here are some important points to note in the code sample:
-
This example assumes that the report has a prompt.
-
The setName() method in Step 1 is not explicitly necessary in this example. However, providing this line allows us to easily persist this bean by our specified name.
-
In Step 2, TransformInstance is added to the PromptsBean, pb, and not the ReportBean, rb.
-
In Step 3, ReportBean rb calls collectData(), PromptsBean pb calls the transform() method.
-
A more dynamic code sample might check to see whether the PromptsBean is NULL before calling transform() on it.