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

KB13060: How to Create an Add-on in MicroStrategy Web SDK 9.x that Executes Only when Using a Specific Project


Community Admin

• Strategy


The MicroStrategy SDK allows useres to customize the standard MicroStrategy Web interface and extend and integrate the MicroStrategy business intelligence functionality into other applications. However, before changing the way MicroStrategy Web products look or behave, it is helpful to understand how the application is built. For more information regarding the MicroStrategy Web architecture or the process of customizing MicroStrategy Web, refer to the MicroStrategy Developer Zone at https://support.microstrategy.com/MSDL/home.asp.

The Strategy SDK allows useres to customize the standard Strategy Web interface and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy Web products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy Web architecture or the process of customizing Strategy Web, refer to the Strategy Developer Zone at https://support.Strategy.com/MSDL/home.asp.
 
To access the Strategy Developer Zone, a user must have access to the Strategy Knowledge Base, must have purchased the Strategy SDK, and must be current on their 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, contact Strategy Technical Support at support@Strategy.com or at (703) 848-8700. If you are an international business, contact Strategy Technical Support at the appropriate email address or phone number found at http://www.Strategy.com/Support/ContactUs.asp.
 
The example provided in this document is provided "as-is" to the user and assumes that the user:

  • can program, compile (e.g. javac, jikes, etc.), and execute Java programs
  • can configure environment variables (e.g. JAR files, property files, etc.)
  • has all the necessary tools to create Java applications (JDK, IDE, etc.)
  • has access to the Strategy SDK documentation.
  • has read the customization warning at the bottom of this document
  • can obtain the qualifying project's name and/or project ID manually or systematically

PREREQUISITES:
For the sample to work, the Strategy Web 9.x JAR files must be accessible by the Java Runtime Environment. The Strategy Web 9.x JAR files can be found under:

  • Strategy Web Universal 9.x (JSP): /WEB-INF/lib directory.
  • Strategy Web 9.x (.NET): Program Files\Common Files\Strategy directory.

NOTE: More elaborate programs will require additional library files and are out of the scope of this document.
 
The following add-on code sample for Strategy Web SDK 9.x demonstrates how to execute custom code for a specific project based on its project ID and/or its project name. The add-on can be executed when clicking 'My Reports', editing a report, executing a report, etc. 
For more information about customizing with Add-ons, click the following link:
https://resource.microstrategy.com/MSDZ/MSDL/930/docs/mergedProjects/websdk/topics/webcusteditor/custtasks/WCE_Creating_a_New_Add-on_for_a_Page.htm#bc-1
Sample Code/Error
package custom.sdk.samples;
import com.Strategy.web.app.addons.*;
import com.Strategy.web.beans.*;
import com.Strategy.web.app.beans.*;
/*
 *
 * The ConditionOnProjectAddOn class is an add-on for Strategy Web that
 * can execute custom code for a specific project based on its
 * project ID and/or its project name.
 *
 * Note: The code used to condition on project id has been commented out on purpose.
 *    This class will demostrate how to execute custom code based on project name.
 */
public class ConditionOnProjectAddOn extends AbstractAppAddOn {
 private final String name = "Tutorial Project";
 // private final String id = "0D9D6DD4444076D4FC729D9C5D4E6EFE";
 
 /**
  * Returns the description for the this addon
  */
 public java.lang.String getAddOnDescription() {
  return "This add on executes code based on a project's Name";
 }
 /**
  * main execution method, passed in an instance of the appropriate page component
  **/
 public void preCollectData(PageComponent pageComponent) {
  
  try {
   //  Obtain Project Name
    String projectName = pageComponent.getAppContext().getAppSessionManager()
     .getActiveSession().getProjectName();
   
    // Obtain Project ID
    // String projectID = pageComponent.getAppContext().getAppSessionManager()
    //  .getActiveSession().getProjectID();
   
   // Obtain the Report Bean that this component represents
   //  The Report Bean will not be used in this example.
   
    ReportBean _rb = getReportBean(pageComponent);
    if (_rb == null)
    return;
   
   // Check if a Prompt Bean exists
   // PromptsBean _pb = _rb.getPromptsBean();
   // if (_pb == null)
   // return;
   
    //Verify that either projectName is valid.
    if (projectName == null || !projectName.equals(name)) {
     return;   // exit if condition fails, else resume.
    }
   // Verify that either projectID is valid.
   //  if (projectID == null ||!projectID.equals(id)) {
   //  return;   // exit if condition fails, else resume.
   //  }
   
   /* The condition is valid, continue executing code */
   
  }
  catch (Exception ex) {
   ex.printStackTrace();
  }
 }
 /*
  * Checks whether a web component is a report bean and returns that
  * bean if found, returning null otherwise.
  * Notice that search is recursive for components below the current
  */
 private static ReportBean getReportBean(WebComponent wc) {
  ReportBean __result = null;
  if (wc instanceof ReportBean) {
   __result = (ReportBean) wc;
  } else {
   for (int i = 0; i < wc.getChildCount(); i++) {
    __result = getReportBean(wc.getChild(i));
    if (__result != null)
     break;
   }
  }
  return __result;
 }
}
 
ConditionOnProjectAddOn
 
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 an Account Executive to inquire about Strategy Consulting assistance.
 


Comment

0 comments

Details

Knowledge Article

Published:

June 22, 2017

Last Updated:

June 22, 2017