Skip to Content

In this blog, I will be demonstrating a program object to export the list of recurring instances in a Business Objects environment.

Prerequisites:

  1. BusinessObjects Enterprise System
  2. BusinessObjects Enterprise Java SDKs

Creation of a Java Program Object:

  • For creating a java program object, you need to write a java class which has to implement the interface IProgramBase.
  • Once you create the java file, you would then need to create a jar file for the java class by setting all the required jars in your classpath.
  • Below is a sample java file to export the list of recurring instances in a BusinessObjects environment

import com.crystaldecisions.sdk.plugin.desktop.program.*;
import com.crystaldecisions.sdk.framework.*;
import com.crystaldecisions.sdk.occa.infostore.*;
import com.crystaldecisions.sdk.exception.*;
import java.io.FileWriter;
import java.io.IOException;
import com.crystaldecisions.sdk.occa.report.lib.PropertyBag;
import com.crystaldecisions.sdk.properties.IProperties;
import com.crystaldecisions.sdk.properties.IProperty;
import com.crystaldecisions.sdk.plugin.desktop.folder.*;
import java.text.*;
import java.util.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.*;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
public class RecurringInstanceInfo implements IProgramBase
{
public void run(IEnterpriseSession enterprisesession,IInfoStore infostore,String str[]) throws SDKException
{
  System.out.println("Connected to " + enterprisesession.getCMSName() + "CMS");
        System.out.println("Using the credentials of " + enterprisesession.getUserInfo().getUserName() );
 
      
  String nextruntime=null;
  String finalFolderPath=null;
  Date convertedDate=null;
  String email=null;
  String CCemail=null;
  XSSFWorkbook wb = new XSSFWorkbook();
  XSSFSheet sheet = wb.createSheet("new sheet");
  XSSFRow rowhead = sheet.createRow((short)0);
  rowhead.createCell((short) 0).setCellValue("INSTANCE ID");
  rowhead.createCell((short) 1).setCellValue("INSTANCE TITLE");
  rowhead.createCell((short) 2).setCellValue("SCHEDULE");
  rowhead.createCell((short) 3).setCellValue("DELIVERY TYPE");
  rowhead.createCell((short) 4).setCellValue("BATCH CATEGORY");
  rowhead.createCell((short) 5).setCellValue("RECEPIENTS");
  rowhead.createCell((short) 6).setCellValue("NEXTRUNTIME");
  int index = 1;
  try
  {
  String statusCheck=null;
  String typeCheck=null;
              
  infostore = (IInfoStore) enterprisesession.getService("", "InfoStore");               
  IInfoObjects infoobjects = infostore.query("SELECT * from CI_INFOOBJECTS WHERE  si_recurring=1");          
  for(int i=0;i<infoobjects.size();i++)
  {
  IInfoObject infoobject=(IInfoObject) infoobjects.get(i);
  ISchedulingInfo schedInfo=infoobject.getSchedulingInfo();
  int instanceID=infoobject.getID();
  String instanceName=infoobject.getTitle();
  String kind=infoobject.getKind();
  System.out.println("<b>Instance ID :</b>"+instanceID+"<br>");
  System.out.println("<b>Instance Name :</b>"+instanceName+"<br>");
  System.out.println("<b>Delivery Type :</b>"+kind+"<br>");
  int type=schedInfo.getType();
  System.out.println("<br><b> Schedule Type :</b><br>");
  switch(type)
  {
  case CeScheduleType.ONCE:
  typeCheck="ONCE";
  System.out.println(typeCheck);
  break;
  case CeScheduleType.HOURLY: //Job has failed.
  typeCheck="HOURLY";
  System.out.println(typeCheck);
  break;
   
  case CeScheduleType.DAILY: //Job is paused.
  typeCheck="DAILY";
  System.out.println(typeCheck);
  break;
   
  case CeScheduleType.WEEKLY: //Job is pending.
  typeCheck="WEEKLY";
  System.out.println(typeCheck);
  break;
   
  case CeScheduleType.MONTHLY: //Job is running.
  typeCheck="MONTHLY";
  System.out.println(typeCheck);
  break;
  case CeScheduleType.NTH_DAY:
  typeCheck="NTH_DAY";
  System.out.println(typeCheck);
  break;
  case CeScheduleType.FIRST_MONDAY: //Job has failed.
  typeCheck="FIRST_MONDAY";
  System.out.println(typeCheck);
  break;
   
  case CeScheduleType.LAST_DAY: //Job is paused.
  typeCheck="LAST_DAY";
  System.out.println(typeCheck);
  break;
   
  case CeScheduleType.CALENDAR: //Job is pending.
  typeCheck="CALENDAR";
  System.out.println(typeCheck);
  break;
   
  case CeScheduleType.CALENDAR_TEMPLATE: //Job is running.
  typeCheck="CALENDAR_TEMPLATE";
  System.out.println(typeCheck);
  break;
  }
  int id=infoobject.getParentID();
  IInfoObjects infoobjects1 = infostore.query("SELECT * from CI_INFOOBJECTS WHERE  si_id="+id);
  IInfoObject infoobject1=(IInfoObject)infoobjects1.get(0);
  String reportName=infoobject1.getTitle();
  int parentid=infoobject1.getParentID();
  IInfoObjects infoobjects2 = infostore.query("SELECT * from CI_INFOOBJECTS WHERE  si_id="+parentid);
  IInfoObject infoobject2=(IInfoObject)infoobjects2.get(0);
  if(infoobject2.getKind().equals("Folder"))
  {
    finalFolderPath="/";
   IFolder iifolder=(IFolder)infoobject2;
 
   if(iifolder.getPath()!= null)
   {
    String path[]=iifolder.getPath();
    for(int fi=0;fi<path.length;fi++)
    {
     finalFolderPath =  "/"+path[fi]+ finalFolderPath;
 
    }
     finalFolderPath = finalFolderPath+iifolder.getTitle();
   }
   else
   {
    finalFolderPath=finalFolderPath+iifolder.getTitle();
   }
   System.out.println("<br><b>Parent Folder Path of The Report :</b>"+finalFolderPath+"<br>");
 
  }
  IProperties instanceProperties=(IProperties)infoobject.properties();
  IProperty instanceProperty=instanceProperties.getProperty("SI_NEXTRUNTIME");
  if(instanceProperty != null)
  {
  nextruntime=instanceProperty.getValue().toString();
  System.out.println("<br><b>Instance Next Run Time :</b>"+nextruntime+"<br>");
  DateFormat readFormat=new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
  convertedDate=readFormat.parse(nextruntime);
  System.out.println("<b>Converted To Date Object :</b>"+convertedDate+"<br>");
  }
  IProperties destinationProperties=(IProperties)infoobject.getSchedulingInfo().properties();
  IProperties destinationProperty=(IProperties)destinationProperties.getProperties("SI_DESTINATIONS");
  if(destinationProperty == null)
  {
  System.out.println("No Property with SI_DESTINATIONS<br>");
  XSSFRow row = sheet.createRow((short)index);
  row.createCell((short) 0).setCellValue(instanceID);
  row.createCell((short) 1).setCellValue(instanceName);
  row.createCell((short) 2).setCellValue(typeCheck);
  row.createCell((short) 3).setCellValue(kind);
  row.createCell((short) 4).setCellValue(finalFolderPath);
  row.createCell((short) 6).setCellValue(nextruntime); 
  }
  else
  {
  IProperties smtpProps=(IProperties)destinationProperty.getProperties("1");
  if(smtpProps != null)
  {
  IProperty smtpProps1=(IProperty)smtpProps.getProperty("SI_PROGID");
  String smtpProps2=smtpProps1.getValue().toString();
  if (smtpProps2.equals("CrystalEnterprise.Smtp"))
  {                 
             
                IProperties pathProperties1=(IProperties)schedInfo.properties().getProperty("SI_DESTINATIONS").getValue();
  IProperty pathProperty2=pathProperties1.getProperty("1");
  if(pathProperty2 == null)
  {
  System.out.println("No Property with name 1<br>");
  }
  else
  {
  IProperties pathProperties2=(IProperties)pathProperties1.getProperty("1").getValue();
  IProperty pathProperty3=pathProperties2.getProperty("SI_DEST_SCHEDULEOPTIONS");
  if(pathProperty3 == null)
  {
  System.out.println("No Property with name SI_DEST_SCHEDULEOPTIONS<br>");
  }
  else
  {
  IProperties pathProperties3=(IProperties)pathProperties2.getProperty("SI_DEST_SCHEDULEOPTIONS").getValue();
  IProperty pathProperty4=pathProperties3.getProperty("SI_MAIL_ADDRESSES");
  if(pathProperty4 == null)
  {
  System.out.println("No Property with name SI_MAIL_ADDRESSES<br>");
  }
  else
  {
  IProperties pathProperties4=(IProperties)pathProperties3.getProperty("SI_MAIL_ADDRESSES").getValue();
  IProperty pathProperty5=pathProperties3.getProperty("SI_MAIL_CC");
  if(pathProperty5 == null)
  {
  System.out.println("No Property with name SI_MAIL_ADDRESSES<br>");
  }
  else
  {
  IProperties pathProperties5=(IProperties)pathProperties3.getProperty("SI_MAIL_CC").getValue();
  String numberofEmails=pathProperties4.getProperty("SI_TOTAL").getValue().toString();
  String numberofCCEmails=pathProperties5.getProperty("SI_TOTAL").getValue().toString();
                                   
    Integer Emails=new Integer(numberofEmails);
  System.out.println("<b>Email Address :</b><br>");                                                            
  for(int temp=1;temp<=Emails.intValue();temp++)
  {
  email=pathProperties4.getProperty(""+temp).getValue().toString();
  System.out.println(pathProperties4.getProperty(""+temp).getValue().toString()+"<br>");
  XSSFRow row = sheet.createRow((short)index);
  row.createCell((short) 0).setCellValue(instanceID);
  row.createCell((short) 1).setCellValue(instanceName);
  row.createCell((short) 2).setCellValue(typeCheck);
  row.createCell((short) 3).setCellValue(kind);
  row.createCell((short) 4).setCellValue(finalFolderPath);
  row.createCell((short) 6).setCellValue(convertedDate);
  XSSFCell cell=row.createCell((short) 6);
  cell.setCellValue(convertedDate);
  XSSFCellStyle cellStyle=wb.createCellStyle();
  //cellStyle.setDataFormat(XSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
  cell=row.createCell((short) 6);
  cell.setCellValue(convertedDate);
  cell.setCellStyle(cellStyle);
  row.createCell((short) 5).setCellValue(email);
  index++;
      }
             
  Integer CCEmails=new Integer(numberofCCEmails);
  System.out.println("<b>CC Email Address :</b><br>");                                                            
  for(int temp1=1;temp1<=CCEmails.intValue();temp1++)
  {
  CCemail=pathProperties5.getProperty(""+temp1).getValue().toString();
  System.out.println(pathProperties5.getProperty(""+temp1).getValue().toString()+"<br>");
  XSSFRow row = sheet.createRow((short)index);
  row.createCell((short) 0).setCellValue(instanceID);
  row.createCell((short) 1).setCellValue(instanceName);
  row.createCell((short) 2).setCellValue(typeCheck);
  row.createCell((short) 3).setCellValue(kind);
  row.createCell((short) 4).setCellValue(finalFolderPath);
  row.createCell((short) 6).setCellValue(convertedDate);
  XSSFCell cell=row.createCell((short) 6);
  cell.setCellValue(convertedDate);
  XSSFCellStyle cellStyle=wb.createCellStyle();
  //cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
  cell=row.createCell((short) 6);
  cell.setCellValue(convertedDate);
  cell.setCellStyle(cellStyle);
  row.createCell((short) 5).setCellValue(CCemail);
  index++;
                }
  }
     }
  }
  }
  }
  else
     {
  System.out.println("Not Applicable For This Instance....!<br>");
     }
  }
        }
    System.out.println("<br>===========================================================<br>");
}
    Date date=new Date();
  String date1= date.toString();
  String date2=date1.replaceAll("\\W", "_");
                FileOutputStream fileOut = new FileOutputStream(str[0]+"_"+date2 +".xlsx");
  wb.write(fileOut);
  fileOut.close();
  System.out.println(" Excel file created successfully");
    }
    catch(Exception e)
  {
  System.out.println(e.getMessage());
  }
}
}
  • Copy the above code into a text file and save it as FailedInstances.java. Please make sure that your java class name and file name should exactly be the same (case sensitive).
  • Compile the above java class by having all the jars required to run the file in the classpath. You can also use eclipse IDE to compile and create jar file. The list of jars can be found from the developers guide available at below links:
    • For BI 4.0:

               http://help.sap.com/businessobject/product_guides/boexir4/en/xi4_boejava_dg_en.zip

    • For XI 3.1

               http://help.sap.com/businessobject/product_guides/boexir31/en/boesdk_java_dg_12_en.zip


  • Refer to the section ‘JAR files needed for deployment of Business Objects Software’ from the above guides to get the list of jar files.
  • You would specifically need the jar files listed under ‘BusinessObjects Enterprise Java SDK’
  • Once you have compiled the code, create a jar file for your compiled .class file.


Publishing the Java Program Object to the Enterprise System:

  1. In the CMC, go to Folders and create new folder “Objects” or navigate to an existing folder where you want to publish the program object
  2. Select the folder “Objects” and click on Manage | Add | Program File
  3. Choose as Program Type Java and add RecurringInstances.jar
  4. Right Click on ServerStatus within your Objects folder and choose Properties | Default Settings | Program Parameters
  5. Specify as “Class to run:” RecurringInstanceInfo.
  6. In the Arguments pass the the location along with excel file name where you want the excel file to be generated(eg. c:/failedinstances.xls).
  7. Test “Run Now” and schedule the Program Object.

You would then have an excel file generated at the above specified location with the details of recurring instances.

To report this post you need to login first.

1 Comment

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

  1. Kaviyarasu Jayavel

    Hi Anchal Verma , thanks for the SDK code. I was looking SDK to change the recurring instance ownership from one user to another user(not to Admin). Would you able to share the code please?

    We are using BOXI3.1SP5 and we have approx. 1000 instances.

     

    Thanks, Kavi

    (0) 

Leave a Reply