MicroStrategy ONE

Removing Template Units from Template

This example demonstrates removing template units from a template.

Code sample

This code sample assumes that the session ID, message ID, and state ID are set in variables named sessionID, messageID, and stateID, respectively.

 //Create and initialize the report source object

 WebObjectsFactory woFact = WebObjectsFactory.getInstance();

 WebIServerSession ss = factory.getIServerSession();

 ss.setSessionID(sessionID);

 ss.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);

 WebReportSource rptSrc = woFact.getReportSource();

 //Obtain a report instance corresponding to the given messageID and stateID

 WebReportInstance rptInst = rptSrc.getInstance(messageID, stateID);
 

 //Set the options on the report instance

 rptInst.setAsync(false); rptInst.setPollingFrequency(250); rptInst.setMaxWait(120000);
 

 //Poll the server until the status is in a final state and ensure that the status is ready before continuing

 int status = rptInst.pollStatus();
 if (status != EnumDSSXMLStatus.DssXmlStatusResult) {
      Log.logger.log(Level.ERROR, "Error: unexpected status:  " + status);
      return;
 }
 

 //Obtain the template from the report instance

 WebTemplate template = rptInst.getTemplate();
 

 //Return the template unit at axis 1, position 0

 WebTemplateUnit tu = template.getTemplateUnit(1, 0); // axis 1, position 0

 

 //Obtain the WebObjectInfo object that is referred to by the WebTemplateUnit object

 WebObjectInfo oiToRemove = (WebObjectInfo)tu.getTarget();
 

 //Remove the given WebObjectInfo object from the template

 template.remove(oiToRemove);

 

 //Obtain the WebReportManipulation interface from the report instance

 WebReportManipulation rptManip = rptInst.getReportManipulator();

 //Submit the changed report to Intelligence Server 

 WebReportInstance newInst = rptManip.applyChanges();