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

KB239042: Adding a custom style to output raw JSON for the reportExecute/reportDataService tasks


Community Admin

• Strategy


This KB article provides steps that can be taken to create a custom style, in order to return raw unformatted JSON from the reportExecute and reportDataService tasks.

The reportExecute and reportDataService tasks allow users to return report data in various formats, by supplying a styleName. 
This technical note provides steps that can be taken to create a custom style, in order to return raw unformatted JSON from these tasks.
 
Note:
In Strategy 10.9 the REST API was introduced. The REST API provides an out-of-the-box API for retrieving report data in JSON format. While the approach below is functional, Strategy recommends that users on Strategy 10.9 and later who interested in consuming data provided by the Strategy platform in JSON format should use the REST API instead.
 
Summary of steps

  1. Create a custom transform to collect the report data and return it in JSON format.
  2. Create a custom style that implements this transform.
  3. Use this custom style for the "styleName" parameter in the reportExecute/reportDataService tasks.

 
Creating the JSON transform

  1. Launch the Web Customization Editor.
  2. Navigate to Application Settings > Strategy Web Configuration > Styles.
  3. Right-mouse click on Styles and select Create Transform to launch the Transform Creation Wizard.
  4. Make the following entries:

    Package: com.Strategy.sdk.samples.transforms
    Name: CustomXMLJSONReportTransform
    Transform Description: This transform returns report data as raw unformatted JSON.
    Superclass: com.Strategy.web.transform.AbstractTransform
     
  5. Click Next.
  6. Click the radio button for "Uncheck all methods".
  7. Click Next.
  8. Click Finish. 

CustomXMLJSONReportTransform.java will open in the editor. The following sample explains the code used in this transform:


/**
 * Strategy SDK Sample
 *
 * Copyright © 2011 Strategy Incorporated. All Rights Reserved.
 *
 * Strategy MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE 
 * SUITABILITY OF THIS SAMPLE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING 
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Strategy SHALL NOT 
 * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, 
 * MODIFYING OR DISTRIBUTING THIS SAMPLE CODE OR ITS DERIVATIVES.
 *
 *
 */


package com.Strategy.sdk.samples.transforms;

import com.Strategy.web.app.tasks.architect.json.*;
import com.Strategy.web.beans.*;
import com.Strategy.web.objects.*;
import com.Strategy.web.transform.AbstractTransform;
import com.Strategy.webapi.EnumDSSXMLResultFlags;

public class CustomXMLJSONReportTransform extends AbstractTransform { 
 
	public String getDescription() {
        return "This transform returns report data as raw unformatted JSON.";
    }

	@Override
	public Class getSupportedBeanType() {
		return ReportBean.class;
	}

	// The transform method is called when output is required from the transform. 
	@Override
	public void transform(Transformable data, MarkupOutput out)	throws ClassCastException {
		
		int PRETTY_PRINT_INDENT_FACTOR = 4;
        
		// Retrieve ReportBean from transform parameter
		ReportBean rb = (ReportBean) data;
        
		try {
			// Without grid, nothing would be returned. rawData adds unformatted metric values.
			rb.setResultFlags(EnumDSSXMLResultFlags.DssXmlResultGrid | EnumDSSXMLResultFlags.DssXmlResultRawData);
			
			// Request data from server
			rb.collectData();
			
			// Retrieve XML from report instance
			WebReportInstance wri = rb.getReportInstance();
			String reportDataXML = wri.getResultsAsXML();
						
			// Retrieve JSON using XML
			JSONObject xmlJSONObj = XML.toJSONObject(reportDataXML);
			String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);

			// jsonPrettyPrintString contains the report results in JSON format. 
			// To output a String object in a transform, it is appended to the MarkupOutput object passed in the method parameter.
	        out.append(jsonPrettyPrintString);
	        
		} catch (WebBeanException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WebObjectsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

 
 
Creating a custom style that implements this transform
To use the custom transform in the reportExecute and reportDataService tasks, a style needs to be created that uses this transform.

  1. Launch the Web Customization Editor.
  2. Navigate to Application Settings > Strategy Web Configuration > Styles.
  3. Right-mouse click on Styles and select New Style to launch the Style Creation Wizard.
  4. Make the following entries:

    Name: CustomXMLJSONReportStyle
    Description: This style implements the custom report JSON transform
    Transform: CustomXMLJSONReportTransform Note: click "New Transform Defn" to select the custom transform if it isn't listed.
     
  5. Click Next.
  6. Click Next.
  7. Click Finish.
  8. Save your changes.
  9. Restart Strategy Web for the changes to take effect.

 
Using this style in the Task Viewer Application
Within the reportExecute or reportDataService tasks ensure that the styleName parameter is included with the value "CustomXMLJSONReportStyle":

ka0PW0000000nvBYAQ_0EM440000002GPA.jpeg

 
This instructs the task to use the custom transform to retrieve the task output.
 
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.)
  • Have 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

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

  • Strategy Web Universal (JSP): {web_root}/WEB-INF/lib directory.
  • Strategy Web (.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.
 
ADDITIONAL INFORMATION:
The Strategy SDK allows you 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, please refer to the MicroStrategy Developer Hub.
 
To access the Strategy Developer Hub, 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 Hub, 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/en/support/contact-support.
 
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.


Comment

0 comments

Details

Knowledge Article

Published:

June 8, 2017

Last Updated:

February 16, 2024