Rescheduling a Paused Job
In SAP Business Objects Enterprise 3.1, if you use the SDK to reschedule a job, if it’s paused, then the rescheduled job ends up NOT being paused. In fact, the same thing happens if you reschedule a paused job from the CMS. So how do you keep that from happening? The magic is in the object’s SI_NEW_JOB_ID property.
When you call IInfoStore.schedule( IInfoObjects ), it updates SI_NEW_JOB_ID for each of the InfoObjects with the SI_ID of the newly scheduled job. Query on that to get the new one.
You have to go back through all of the original jobs anyway to delete them, so while you’re there, check to see if they’re paused. If they are, get SI_NEW_JOB_ID and do a new query on it to get the new one then call ISchedulingInfo.setFlags( ISchedulingInfo.ScheduleFlags.PAUSE ) to pause it. (Be sure to commit it back to the CMS.) The new one is now paused and you can delete the old one.
Something to be aware of is that SI_NEW_JOB_ID is valid ONLY for the SDK, and only for the actual objects that were sent in to schedule(). If you re-query those jobs or if you use Query Builder to look at them, SI_NEW_JOB_ID will always point to its own SI_ID. This is because schedule() updates the objects, but doesn’t write them back to the CMS.
Here’s a Java sample on how to do this. A .NET sample would operate on the same principles.
Schedule a paused job:
<%@ 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 ) ;
// if the job is paused, pause the new one too
if ( scheduleInfo.getStatus() == ISchedulingInfo.ScheduleStatus.PAUSED ) {
out.println( " (paused)" );
// Find the new one
String newQuery = "Select Top 1 * "
+ "From CI_INFOOBJECTS "
+ "Where SI_ID=" + oReport.properties().get("SI_NEW_JOB_ID") ;
IInfoObjects oNewObjects = infoStore.query( newQuery ) ;
IInfoObject oNewReport = (IInfoObject) oNewObjects.get( 0 ) ;
ISchedulingInfo newScheduleInfo = oNewReport.getSchedulingInfo() ;
// Pause it
newScheduleInfo.setFlags( ISchedulingInfo.ScheduleFlags.PAUSE ) ;
// Update it
infoStore.commit( oNewObjects ) ;
}
// 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.