Skip to Content

Sometimes as an administrator you need to reschedule someone else’s reports, say because everybody’s bunched their reports at 2am and you’d like to move some of them to 4, or something like that. You can certainly use code to do that, but the problem is, when you do, it ends up owned by you instead of the original owner. The reason for this is because you don’t technically reschedule a report – you actually duplicate an existing one, making any changes you want along the way, then deleting the old one. Thing is, now you own a scheduled job that really belongs to someone else.

What you’re looking for is ISchedulingInfo.setScheduleOnBehalfOf(). This Enterprise SDK API allows you to schedule a report using someone else’s user ID. In an existing schedule, this is held in the SI_OWNERID property. Reschedule it on behalf of that and you’re set.

Schedule on behalf of:

<%@ page import = "com.crystaldecisions.sdk.occa.infostore.*" %>
<%@ page import = "com.crystaldecisions.sdk.framework.CrystalEnterprise" %>
<%@ page import = "com.crystaldecisions.sdk.exception.SDKException" %>
<%@ page import = "com.crystaldecisions.sdk.framework.IEnterpriseSession" %>
<%
    // logon information
    String boCmsName  = "localhost" ;
    String boUsername = "administrator" ;
    String boPassword = "" ;
    String boAuthType = "secEnterprise" ;
   
    // report
    String reportName = "[MyReportToReschedule]" ;
   
    // logon
    IEnterpriseSession ceSession = CrystalEnterprise.getSessionMgr().logon( boUsername, boPassword, boCmsName, boAuthType ) ;
    IInfoStore         infoStore = (IInfoStore)ceSession.getService( "", "InfoStore" ) ;
    // get the scheduled report
    String cr_query = "Select Top 1 * "
                      + "From CI_INFOOBJECTS "
                      + "Where SI_NAME='" + reportName + "' "
                      + "and SI_INSTANCE=1 and SI_RECURRING=1 " ;
    IInfoObjects oInfoObjects = infoStore.query( cr_query ) ;
    if ( oInfoObjects.size() == 0 ) {
       out.println( "<b>Scheduled report not found: '" + reportName + "'</b><br />" ) ;
       ceSession.logoff() ;
       return ;
    }
  
    IInfoObject     oReport      = (IInfoObject) oInfoObjects.get( 0 ) ;
    ISchedulingInfo scheduleInfo = oReport.getSchedulingInfo() ;
    out.println( oReport.properties().get("SI_OWNER") + " '" + oReport.getTitle() + "'<br />" ) ;
    try {
       // any changes to the schedule would go here
       // schedule it for the correct (original) owner
       scheduleInfo.setScheduleOnBehalfOf( Integer.parseInt(oReport.properties().get("SI_OWNERID").toString()) ) ;
     
       // scheduling creates a new (duplicate) schedule based off the existing one
       infoStore.schedule( oInfoObjects ) ;
     
       // Delete the original scheduled report
       oInfoObjects.delete( (IInfoObject)oInfoObjects.get(0) ) ;
     
       // Write the changes to the CMS
       infoStore.commit( oInfoObjects ) ;
       out.println( "<br />Report rescheduled" ) ;
    } catch ( SDKException e ) {
       out.println( "<font color=red><b>couldn't reschedule report</b></font><br />" ) ;
       out.println( e.toString() ) ;
    }
    // logoff
    ceSession.logoff() ;
%>

Until next time.

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