Skip to Content
SBOP SDK

Base Scripting Template for Crystal Reports

Tags:

When using SAP BusinessObjects Enterprise, there are times where it is useful to perform an action on all objects of a particular type.  For example, if you want to delete all instances of a report, or you want to remap the universes for all webi reports.  For these types of tasks, a script can be very useful and significantly faster than making the changes manually.

The code below can be used as a template for looping through all crystal reports on an enterprise system and opening them using RAS to perform some kind of modification.  This code will work on a BOE XI 3.1 and a BI4 system.

Code Sample

<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
com.crystaldecisions.sdk.framework.*,
com.crystaldecisions.sdk.occa.infostore.*,
com.crystaldecisions.sdk.occa.report.*,
com.crystaldecisions.sdk.properties.*,
com.crystaldecisions.sdk.occa.report.application.*,
com.crystaldecisions.sdk.occa.managedreports.*,
com.crystaldecisions.sdk.occa.report.data.*,
java.util.*"
%>
<%
// User Credentials
String username = "Administrator";
String password = "myPassword";
String cmsname  = "myEnterpriseServer";
String authType = "secEnterprise";

IEnterpriseSession enterpriseSession = null;
IInfoStore infoStore;
IInfoObjects boInfoObjects;

// Log onto Enterprise
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

// The SI_ID to start at when searching
int max_id = 0;

// Obtain the necessary RAS factory for opening reports.
IReportAppFactory reportAppFactory=(IReportAppFactory) enterpriseSession.getService("","RASReportService");

for(;;) {

// Loop through all objects
boInfoObjects = (IInfoObjects)infoStore.query("Select * FROM CI_INFOOBJECTS WHERE SI_KIND='CrystalReport' AND SI_ID > " + max_id + " ORDER BY SI_ID ASC");

// If there are no more objects then we're done.
if(boInfoObjects.size() == 0)
break;

for(Iterator boCount = boInfoObjects.iterator() ; boCount.hasNext() ; ) {
  IInfoObject boReport = (IInfoObject)boCount.next();
 
  // Open the report with RAS
  ReportClientDocument rcDocument=reportAppFactory.openDocument(boReport.getID(),0,Locale.ENGLISH); 

  // Here is where you would do all the needed work / modifications
  rcDocument.save();  // If you made any changes that need to be saved you would include this line.
  rcDocument.close();
  max_id = boObject.getID();
}
infoStore.commit(boInfoObjects);
}
out.println("Completed</br>");

%>

No comments