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
Creating the JSON transform
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();
}
}
}
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":

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:
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:
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.