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

KB14807: How to display the metric formula in the header of a metric in Microstrategy Web


Community Admin

• Strategy


Article outlines how to customize MicroStrategy Web to display the metric formula in the header

By using a transform, metric headers can be modified to display the formula of simple metrics with the metric name when executing reports in Strategy Web
NOTE: This customization will only work for metrics that do not contain prompts. Only the formula will be displayed and not the filtering criteria or level, as shown below:
 

ka04W000000Oed2QAC_0EM440000002H0J.jpeg

 
To achieve this customization, follow the steps below:

  1. Backup the file gridClasses.properties located under \WEB-INF\classes\resources.
  2. In gridClasses.properties, replace the following line:
    colHeader=com.Strategy.web.app.transforms.ReportGridCellColHeaderImpl
    Replace the line with:
     
    colHeader=com.Strategy.sdk.transforms.RevenueReportGridCellColHeaderImpl.
    (your custom transform)
  3. Create a new java file called RevenueReportGridCellColHeaderImpl.java under the source folder for custom code. For more information on customizations in Strategy, visit the Strategy Developer Library at:
    http://developer.microstrategy.com
     
  4. The code for the RevenueReportGridCellColHeaderImpl.java file should be as follows:
    
    package com.Strategy.sdk.transforms;
    
    import com.Strategy.web.app.transforms.ReportGridCellColHeaderImpl;
    import com.Strategy.web.beans.MarkupOutput;
    import com.Strategy.web.beans.ViewBean;
    import com.Strategy.web.objects.WebHeader;
    import com.Strategy.web.objects.WebMetric;
    import com.Strategy.web.objects.WebMetricHeader;
    import com.Strategy.web.objects.WebObjectSource;
    import com.Strategy.webapi.EnumDSSXMLObjectFlags;
    import com.Strategy.webapi.EnumDSSXMLObjectTypes;
    
    public class RevenueReportGridCellColHeaderImpl extends ReportGridCellColHeaderImpl {
    
        public RevenueReportGridCellColHeaderImpl() {
            super();
            
        }
    	
        public void generateText(MarkupOutput mo) {
            String colHeader = getText();
            WebHeader header = getWebHeader();
            ViewBean rb = (ViewBean) this.getBaseBean();
            WebObjectSource wos = rb.getSessionInfo().getFactory().getObjectSource();
            
            try {
                String userName = rb.getSessionInfo().getUserInfo().getDisplayName();
                
                if (userName.equals("Administrator")) {
                    try {
                        WebMetricHeader wmh = (WebMetricHeader) header;
                        WebMetric wm;
                        
                        wm = wmh.getWebMetric();
                        wos.setFlags(EnumDSSXMLObjectFlags.DssXmlObjectDefn);
                        WebMetric woi = (WebMetric) wos.getObject(wm.getID(), EnumDSSXMLObjectTypes.DssXmlTypeMetric, true);
                        
                        mo.append(colHeader);
                        mo.append("<br>f(x):" + extractFormula(woi.getXML(), "exp"));
                        
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    } catch (IndexOutOfBoundsException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    
                } else {
                    mo.append(colHeader);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        private String extractFormula(String mXml, String tagName) {
            String metricXml = mXml;
            String tagValue;
            
            if (metricXml.indexOf("<" + tagName) != -1) {
                int startFormulaTag = metricXml.indexOf("<" + tagName);
                int startFormulaText = metricXml.indexOf(">", startFormulaTag) + 1;
                int endFormulaText = metricXml.indexOf("<", startFormulaText);
                
                tagValue = metricXml.substring(startFormulaText, endFormulaText);
            } else {
                tagValue = "No Metric Formula";
            }
            
            return tagValue;
        }
    }

  5. Compile the above code and make sure the destination folder for the compiled class is \WEB-INF\classes\com\MicroStrategy\sdk\transforms.
  6. Restart the Web Application Server.

The code provided only displays the metric formula when the administrator user is logged in.
 
Customization Code 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 may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build.
 


Comment

0 comments

Details

Knowledge Article

Published:

June 8, 2017

Last Updated:

June 8, 2017