MicroStrategy ONE

Converting a Report to a Data Mart Report Using Objects and Beans

The following code sample illustrates how to convert an existing report instance to a data mart report instance, using objects and beans. This code converts the report, but does not save the report definition. This code sample works only with non-prompted reports, or prompted reports that have already been answered.

Code sample

This code sample assumes that a valid report instance exists. Otherwise, it throws an exception.

 public voidconvertToDatamart() throws Exception{

   //create a report bean instance of a normal report, that is, a report that has not been set as a data mart report

   //Sample code for the getReportBean method is provided for you in the Examples topic

   ReportBean rb = getReportBean("Sample Report1");

   WebReportInstance inst = rb.getReportInstance();

 

   //Retrieves the report information and associates the report with a data mart.

   //The boolean parameter for the getDatamartInfomethod indicates whether

   //the current report instance should be converted into a data mart report instance if it is not already one.

   //In this sample code, the parameter is set to true, indicating that conversion should take place.

   //If the code in this line returns true, it gives you the WebDatamart interface.

   WebDatamart datamart = inst.getDatamartInfo(true);

 

   //returns the available database connections

   WebFolder dbRoles = rb.getSessionInfo().getFactory().getObjectSource().getAvailableDBRoles();

  

   //Choose the appropriate database role

   //Sets the connection information that is used for this data mart.

   //In this sample code, the first database connection in the list is used

   datamart.setDBRole(dbRoles.get(0));

 

   //access the table information - creates a data mart table instance

   //If true is returned, it gives you the WebDatamartTable interface.

   WebDatamartTable table = datamart.getTable();

 

   //set table properties - sets the name of the data mart table that is

   //generated when the data mart report is executed (first argument) and specifies

   //whether the name contains macros that need to be replaced during execution (second argument).

   //In this sample code, the name of the report/table is "Datamart1" and it does not contain macros

   table.setName("Datamart1",false);

 

   //specifies whether a new table should be created when the data mart report is executed,

   //or the results of the execution appended to the existing table.

   //If 'true', append the table; if 'false', create a new table. In this sample code, a new table is created.

   table.setAppendToTable(false);

 

   //this forces changes to be applied, which converts the report to a datamart report

   //Note that the report must be saved in order to be converted to a datamart report

   //needs to be reflected for subsequent executions of the report

   rb.collectData();

 }