Scheduling to a Destination

By default when a report is scheduled inside Crystal Enterprise, the resulting file is stored inside the Crystal Enterprise repository. In addition to this, scheduler has the capability to write the report to an arbitrary folder on the machine, e-mail the report to an individual or group, and upload the file to another machine via ftp. The destination is set as part of the scheduled job. From the ISchedulingInfo interface, there is a getDestination method that is used to get access to the IDestination interface. The setFromPlugin method accepts a handle to a destination type object called an IDestinationPlugin. Don't worry about the code required to create the plug-in object, which is covered in the next chapter. The types of destination plug-ins are

For more information on the code required to create the plug-in, see Chapter 36, “Creating Enterprise Reporting Applications with Crystal Enterprise Part II.”

  • CrystalEnterprise.DiskUnmanaged (arbitrary folder location)

  • CrystalEnterprise.Smtp (e-mail)

  • CrystalEnterprise.Ftp (FTP server upload)

The following code shows a report being scheduled once to the Temp folder of the machine:

ISchedulingInfo sched = report.getSchedulingInfo();
sched.setRightNow(true);
IDestination dest = sched.getDestination();
IDestinationPlugin disk = getDestinationPlugin(iStore,
    "CrystalEnterprise.DiskUnmanaged");
IDiskUnmanagedOptions options =
    (IDiskUnmanagedOptions) disk.getScheduleOptions();
options.getDestinationFiles().add("C:/Temp/");
dest.setFromPlugin(disk);
iStore.schedule(results);

Each type of destination has its own corresponding set of options. In the case of the DiskUnmanaged destination, it has an object called IDiskUnmanagedOptions that accepts a folder location as well as optional credentials used to access that folder. The Smtp destination has an ISMTPOptions object that specifies mail routing information. Finally, the Ftp destination has an IFTPOptions object that specifies server, port, credentials, and the target folder:

ISchedulingInfo sched = report.getSchedulingInfo();
sched.setRightNow(true);
IDestination dest = sched.getDestination();
IDestinationPlugin smtp = getDestinationPlugin(iStore, "CrystalEnterprise.Smtp");
ISMTPOptions options = (ISMTPOptions) smtp.getScheduleOptions();
options.setDomainName("domain_name");
options.setServerName("smtp_server_name");
options.setPort(25);
options.setSMTPAuthenticationType(ISMTPOptions.CeSMTPAuthentication.NONE);
options.setSMTPUserName("domainusername");
options.setSMTPPassword("password");
options.setSenderAddress("[email protected]");
options.setSubject("The report '%SI_NAME%' ran successfuly");
dest.setFromPlugin(smtp);
iStore.schedule(results);

Note that in the call to the setSubject method, the string uses the %SI_NAME% variable. Crystal Enterprise replaces this placeholder with the name of the report. This means that the code can be written fairly generically.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.129.194