Skip to Content

This document provides a way to set parameters in a crystal report included in a publication using Business Intelligence platform Java SDK. The sample code sets the parameter value for a crystal report and saves it back to publication.

Warning

The code given below can be very destructive if not used properly.  Please ensure that you have made a backup of your CMS database and your Input and Output FRS prior to running any code.

For more scripts and information on how to run these scripts refer to the blog avaiable here:

http://scn.sap.com/people/shawn.penner/blog/2013/06/04/scripts-and-samples

Below is the Java Server Pages (JSP) sample

Notes:

•You would need to change the userName, password, cmsName and publicationName and the report name to the values specific to your enterprise server in the provided sample code.

• The sample code is tested with BI 4.0 version of SAP BusinessObjects Platform.

<%
/*===================================================================
Creation Date - Oct 15, 2013
Description -   The sample application demonstrates how to assign a current 
    value to a report parameter in a publication
==================================================================*/
%>
<%@ page import="com.businessobjects.sdk.plugin.desktop.profile.*" %>
<%@ page import="com.businessobjects.sdk.plugin.desktop.publication.*" %>
<%@ page import="com.businessobjects.sdk.plugin.desktop.common.*" %>
<%@ page import="com.crystaldecisions.sdk.exception.SDKException" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.*" %>
<%@ page import="com.crystaldecisions.sdk.framework.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.common.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.folder.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.report.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.user.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.usergroup.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.destination.managed.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.destination.smtp.*" %>
<%@ page import="com.crystaldecisions.sdk.plugin.CeProgID" %>
<%@ page import="com.crystaldecisions.sdk.plugin.CeKind" %>
<%@ page import="com.crystaldecisions.sdk.properties.*" %>
<%@ page import="com.crystaldecisions.sdk.occa.pluginmgr.*" %>
<%@ page import="java.util.*" %>
<%
 //Retrieve the logon information
    String boUser ="username";
    String boPassword = "password";
    String boCmsName = "cmsname";
    String boAuthType ="secEnterprise";
   
    String publication_name = "publication_name";
    String report_name ="report_name_in_publication";
%>
<%
    // Logon and obtain an Enterprise Session
    IEnterpriseSession boEnterpriseSession = null;
    boEnterpriseSession = CrystalEnterprise.getSessionMgr().logon( boUser, boPassword, boCmsName, boAuthType);
    session.setAttribute( "boEnterpriseSession", boEnterpriseSession);
%>
<%
    IInfoStore boInfoStore=null;
    IInfoObjects boInfoObjects=null;
    IInfoObject boInfoObject=null;
    IInfoObjects boInfoObjects2=null;
    IInfoObject boInfoObject2=null;
 IPluginMgr pluginMgr = null; //Plugin Manager returned from InfoStore
    IPluginInfo reportPlugin = null; //Report PluginInfo object
    IInfoObjects newInfoObjects = null; //new collection created from InfoStore
    IInfoObject newInfoObject = null;
  try{
     //Retrieve the InfoStore object
     boInfoStore = (IInfoStore) boEnterpriseSession.getService("", "InfoStore");
    
     // Retrieve the desired publication
     boInfoObjects = boInfoStore.query("SELECT * FROM CI_INFOOBJECTS WHERE SI_KIND = '" + CeKind.PUBLICATION + "' AND SI_NAME = '" + publication_name + "' AND SI_INSTANCE=0");
     boInfoObject = (IInfoObject)boInfoObjects.get(0);
    
  IPublication boPublication = (IPublication)boInfoObject;
 
  //Retrieve the requested report  (If you know the SI_ID of the report - you can skip this step which just gets the ID)
  boInfoObjects2 = boInfoStore.query("Select SI_ID, SI_KIND, SI_PROCESSINFO FROM CI_INFOOBJECTS WHERE SI_NAME='" + report_name + "' AND SI_INSTANCE=0");
  boInfoObject2 = (IInfoObject)boInfoObjects2.get(0);
  int documentID = new Integer(boInfoObject2.getID());
  String documentKind = boInfoObject2.getKind();

 
  // Now create a blank crystal report object
  // Note: Because publications store a custom processing info collection, while still pointing back at the original report, it is possible for the
  // two to become de-synchronized.  As a result, it is preferable to re-import the original report when modifying properties.  However, if you want
  // to just update in place - then you can use the code below.
 
  //Retrieve the PluginManager and use it to retrieve Crystal Report plug-in.
        pluginMgr = boInfoStore.getPluginMgr();
        reportPlugin = pluginMgr.getPluginInfo("CrystalEnterprise.Report");
        //Create a new, empty InfoObjects collection.
        newInfoObjects = boInfoStore.newInfoObjectCollection();
        //Add the plug-in to the collection.  This creates a new InfoObject that represents a new Report
        newInfoObject = newInfoObjects.add(reportPlugin);
  IReport crystalReport=(IReport)newInfoObject;
 
 
  // Now retrieve any custom processing properties and add them into the infoobject
  com.crystaldecisions.sdk.properties.IProperties processingProperties = boPublication.getDocumentProcessingInfo(documentID);
  crystalReport.getProcessingInfo().properties().putAll(processingProperties);
  
  // Now retrieve the processing info for the desired report.
  //
  // Note:
  // If this object was a webi report, then we would cast it to an IWebiFormatInfo object, or IFullClientFormatInfo object for Deski
  IReportProcessingInfo boProcessingInfo = (IReportProcessingInfo)crystalReport;
  
  // Now retrieve the report parameters collection
 
  List boParamList = (List)boProcessingInfo.getReportParameters();
 
  // Now loop through the parameters and set values.
  for (Iterator i = boParamList.iterator(); i.hasNext();)
  {
   
   IReportParameter boParam = (IReportParameter)i.next();
   IReportParameterValues boCurrentValues = boParam.getCurrentValues();
   boCurrentValues.clear();
   IReportParameterSingleValue boSingleValue = boCurrentValues.addSingleValue();
   boSingleValue.setValue("This is a parameter Value");
  }
    
  // Save everything back  
     boPublication.setDocumentProcessingInfo(documentID, documentKind, crystalReport.getProcessingInfo().properties());
 
     // Save the publication
  boPublication.save();

     out.println("Publication Succesfully Modified");
    } finally {
     /*
      * Ensure clean-up of the Enterprise session.
      */

     if(boEnterpriseSession != null) {
         try {
             boEnterpriseSession.logoff();
         } catch(Exception e_ignore_in_cleanup) {}
     }
 }
%>
To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply