cancel
Showing results for 
Search instead for 
Did you mean: 

Pause a scheduled instance

Former Member
0 Kudos

How do I pause a scheduled recurring instance with Java SDK? I have a java class that lists all failed instances, and I would like to pause any recurring instances that fail every time they run. Sample code would be great.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member185028
Active Participant
0 Kudos

Hello Bill.

The fiollowing sample should do the trick:


<%
   /* 
    * Description:  	This sample demonstrates how to pause a recurring instance.
    */
%>

<%@ page import = "com.crystaldecisions.sdk.framework.*,
				   com.crystaldecisions.sdk.occa.infostore.IInfoStore,
				   com.crystaldecisions.sdk.occa.infostore.ISchedulingInfo.ScheduleFlags,
				   com.crystaldecisions.sdk.occa.infostore.IInfoObject,
				   com.crystaldecisions.sdk.occa.infostore.IInfoObjects,
				   com.crystaldecisions.sdk.framework.IEnterpriseSession,
                   com.crystaldecisions.sdk.framework.CrystalEnterprise"
%>

<%
	// Declarations
	
	// Business Object Declarations.
	IEnterpriseSession boEnterpriseSession = null;
	ISessionMgr boSessionMgr = null;
	IInfoStore boInfoStore = null;
	IInfoObjects boInfoObjects = null;
	
	// Logon Information
	String userName = "<Enter your user ID here>";
	String cmsName = "<Enter your CMS name here>";
	String password = "<Enter your password here>";
	String authType = "<Enter your authentication type here - for example, secEnterprise>";
	
	// Try block that will catch an Exception.
	try 
	{	
		// Initialize the Session Manager by getting it from the Crystal Enterprise
		// class's getSessionMgr function.
		boSessionMgr = CrystalEnterprise.getSessionMgr();
		
		// Logon to the Session Manager to create a new BOE session.  Pass in the
		// user name, password, the CMS name, and the authentication
		// type.
		boEnterpriseSession = boSessionMgr.logon(userName, password, cmsName, authType);

		// Set the ID of the recurring instance.
		String recurringInstanceID = "<Enter the ID of the recurring instance here>";
		
	    //Retrieve the InfoStore object
	    boInfoStore = (IInfoStore) boEnterpriseSession.getService("", "InfoStore");

    	// Set up the query string.
		String queryString = "SELECT * FROM CI_INFOOBJECTS WHERE SI_INSTANCE = 1 AND SI_RECURRING = 1 AND SI_ID = " + recurringInstanceID;
    	
	   	// Execute the query of the InfoStore.
	    boInfoObjects = boInfoStore.query(queryString);
	   			   	
	   	// If no InfoObjects are returned, then display an appropriate message.
	   	if (boInfoObjects.size() == 0)
	   	{		   	 
	   		out.println("<br \\>Could not find recurring instance with SI_ID = " + recurringInstanceID);
	   	}
	   	else
	   	{
			// Get the current entry from the boInfoObjects
			IInfoObject boIInfoObject = (IInfoObject) boInfoObjects.get(0);
						
			// Pause the recurring instance.
			boIInfoObject.getSchedulingInfo().setFlags(ScheduleFlags.PAUSE);
			
			boInfoStore.commit(boInfoObjects);
			
			// Print out the ID and an indication as to whether the instancce
			// is recurring or not.
			out.println("<br \\>Recurring Instance with ID " + recurringInstanceID + " has been paused.<br \\>");
		}
	}
	catch (Exception ex)
	{
		// Set the message to be displayed to the user to indicate that an
		// error has occurred and display the error message.
		out.println("An error was encountered.  A description of the error"
				+ " is as follows:  " + ex.toString());
		// Log the error and the stack trace to the system out log file
		System.out.println("An error was encountered.  A description of the "
						+ "error is written below:");
		System.out.println(ex);
		System.out.println("The stack trace for the error is written below:");
		ex.printStackTrace(System.out);
	}
	
	// If the logon was previously successful, then logoff.
	if (boEnterpriseSession != null)
	{
		boEnterpriseSession.logoff();
	}
%>

Regards.

- Robert

Answers (0)