EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB34036: How to Answer an Elements Prompt in a Custom Prompt Event Handler using the MicroStrategy Java Web SDK 9.4.1


Community Admin

• Strategy


Java example demonstrating how element prompt answers can be set within a custom prompt event handler in the MicroStrategy Web SDK.

The following code demonstrates how to programmatically answer an element prompt within an event handler using the Strategy Java Web SDK.


package customclasses.handlers;

import com.Strategy.web.beans.AggregatedEventHandler;
import com.Strategy.web.beans.PromptsBean;
import com.Strategy.web.beans.ReportBean;
import com.Strategy.web.beans.RequestKeys;
import com.Strategy.web.beans.WebBeanException;
import com.Strategy.web.beans.WebEvent;
import com.Strategy.web.beans.WebException;
import com.Strategy.web.objects.WebElements;
import com.Strategy.web.objects.WebElementsPrompt;
import com.Strategy.web.objects.WebPrompt;
import com.Strategy.web.objects.WebPrompts;

public class CustomPromptEventHandler extends AggregatedEventHandler {

	public CustomPromptEventHandler() {
		super();
		//this line signifies prompt type handler.
		this.setHandlerType(8);
	}
	public boolean processRequest(RequestKeys keys) throws WebException {

		System.out.println("Entering mycustom event handler");


		WebEvent event = getWebEvent(keys);
		System.out.println(event);
		if (event == null) {
			System.out.println("null Entering mycustom event handler");
			return super.handleDefaultRequest(keys);
		} else {
			System.out.println("null Entering mycustom event handler");
		}

		PromptsBean pb = null;
		ReportBean rb = null;

		//answer prompt for report: ID = B03E01874A35ED80F75F7D8DF148ED62
		//check to make sure this is the report before preceeding
		pb = (PromptsBean) getWebComponent();
		rb = (ReportBean) pb.getParent();
		try {
			if (!rb.getObjectID().equalsIgnoreCase("B03E01874A35ED80F75F7D8DF148ED62")) {
				System.out.println("Entering mycustom event handler");
				return super.handleDefaultRequest(keys);
			} else {
				System.out.println("calling else");
			}
		} catch (WebBeanException wbe) {
			wbe.printStackTrace();
		}

		System.out.println("continue");
		/*The following Object IDs represent the Employee Attribute ID and the Prompt ID.Hardcoding it here
		 * because this prompt object will be associated to my custom style. This information can always be dynamically retrieved.
		 */
		String EmpAttID = "8D679D3F11D3E4981000E787EC6DE8A4";
		String CustomPromptID = "BCC357384DD9A4C97BEFCDA94D34CBB6";

		//format 8D679D3F11D3E4981000E787EC6DE8A4;8D679D3F11D3E4981000E787EC6DE8A4:ID:LastName:FirstName
		//sample: &elementsPromptAnswers=8D679D3F11D3E4981000E787EC6DE8A4;8D679D3F11D3E4981000E787EC6DE8A4:1:Bates:Michael;8D679D3F11D3E4981000E787EC6DE8A4:100:test:test
		switch (event.getID()) {
			case 8001:
				//AnswerAllPrompts event triggered

				String name;
				String val;
				for (int i = 0; i < keys.getNameCount(); i++) {
					name = keys.getName(i);
					val = keys.getValue(name);
					System.out.println(name + " = " + val);
				}
				//Get prompt answers from RequestKeys
				String ElemAnswers = keys.getValue("Emps");
				if (ElemAnswers == null) {
					return super.handleDefaultRequest(keys);
				}

				WebPrompts wps = pb.getPrompts();
				System.out.println("Prompts Count: " + wps.size());
				WebPrompt wp = null;
				WebElementsPrompt wep = null;
				WebElements wes = null;

				//The following loop will iterate through the prompts collection and locate our custom prompt
				for (int x = 0; x < wps.size(); x++) {
					wp = wps.get(x);
					if (wp.getID().equalsIgnoreCase(CustomPromptID)) {
						//build answer for custom prompt
						wep = (WebElementsPrompt) wp;
						wes = wep.getAnswer();
						//clear whatever might currently be there
						wes.clear();
						System.out.println(EmpAttID + ":" + ElemAnswers);
						//add the new answer. This assumes I have one element. if there are more than 1 answers, then iterate through the
						//list and call wes.add(..) for each employee element.
						wes.add(EmpAttID + ":" + ElemAnswers);
					}
				}
				return super.handleDefaultRequest(keys);
			default:
				System.out.println("other event called:" + event.getID());
				return super.handleDefaultRequest(keys);
		}
	}
}

The example provided in this document is provided “as-is” and user has read the following customization warning:
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize several Strategy products and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy products or the process of customizing Strategy products, please refer to Strategy Developer Zone (https://developer.microstrategy.com).
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@microstrategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.microstrategy.com/us/services/support/contact.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
34036


Comment

0 comments

Details

Knowledge Article

Published:

April 17, 2017

Last Updated:

March 24, 2019