ScheduleToDestination.csp


<%@ Language=JavaScript%>

<%

    /*

        This page is called from DestinationOptions.csp.  It schedules the chosen report

        and sends the instance to the destination specified by the user.

    */

%>

<!-- #include file="RetrieveIStore.csp" -->

<!-- #include file=helper_js.csp -->


<html>

<body>

<%


function ScheduleToFTP(IStore,ReportId, ServerName, AccoutName, UserName, Password, FilePath, Port)

/*

    Schedule the report and send the instance to a server via FTP.

*/

{

    // Get the report.

    var Reports = IStore.Query("SELECT SI_ID, SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID="+ReportId);

    if (Reports.Count == 0)

    {    

        return;

    }

    var Report=Reports.Item(1);

    

    var ScheduleInfo ;

    //Create an interface to the scheduling options for the report.

    ScheduleInfo = Report.SchedulingInfo;

    // Run the report once.

    ScheduleInfo.Type = 0;

    // Run it right now.

    ScheduleInfo.RightNow = true;

    

    // Set the FTP options.

    var FTPSchedulingOptions;

    var FTP;

    // Get the FTP InfoObject from the APS.  Note that the SI_PARENTID will always be 29.

    FTP = IStore.Query("Select SI_DEST_SCHEDULEOPTIONS From CI_SYSTEMOBJECTS Where SI_PARENTID=29 and SI_NAME='CrystalEnterprise.FTP'").Item(1);

    

    // Get the actual FTP object and its ScheduleOptions from the FTP plugin.

    // These will be empty.

    FTPSchedulingOptions = FTP.PluginInterface("").ScheduleOptions;

    

    // Set the options.

    // The account name is usually not necessary for some FTP servers.

    FTPSchedulingOptions.Account = AccoutName;

    FTPSchedulingOptions.ServerName = ServerName;

    FTPSchedulingOptions.UserName = UserName;

    FTPSchedulingOptions.Password = Password;

    FTPSchedulingOptions.DestinationFiles.Add (FilePath);

    FTPSchedulingOptions.Port = Port;

    

    // Copy the properties from the FTP object into the report's scheduling

    // information.  This will cause the file to be transfered via FTP after it has been

    // run.

    ScheduleInfo.Destination.SetFromPlugin (FTP);

    

    //Tell the APS to schedule the report.

    IStore.Schedule (Reports);

}


function ScheduleToSMTP(IStore,ReportId, DomainName, ServerName, Subject, SenderAddress, RecipientAddresses, Port, Attachment, CCAddresses, Body, Authentication, UserName, Password)

/*

    Schedule the report and send the instance to a server via email.

    

    PARAMETERS

    

    RecipientAddresses [Array]

    A JavaScript array of strings that contain the recipient addresses, those that will go on the To line.

    

    CCAddresses [Array]

    A JavaScript array of strings that contain the recipient addresses, those that will go on the CC line.

*/

{

    // Get the report.

    var Reports = IStore.Query("SELECT SI_ID, SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID="+ReportId);

    if (Reports.Count == 0)

    {    

        return;

    }

    var Report=Reports.Item(1);

    

    var ScheduleInfo ;

    //Create an interface to the scheduling options for the report.

    ScheduleInfo = Report.SchedulingInfo;

    // Run the report once.

    ScheduleInfo.Type = 0;

    // Run it right now.

    ScheduleInfo.RightNow = true;

    

    // Set the SMTP options.

    var SMTP;

    var SMTPSchedulingOptions;

    // Get the SMTP InfoObject from the APS.  Note that the SI_PARENTID will always be 29.

    SMTP = IStore.Query

    ("Select SI_DEST_SCHEDULEOPTIONS From CI_SYSTEMOBJECTS Where SI_PARENTID=29 and SI_NAME='CrystalEnterprise.SMTP'").Item(1);

    // Get the actual SMTP object and its ScheduleOptions property from the plugin interface.

    // It will be empty at this point.

    SMTPSchedulingOptions = SMTP.PluginInterface("").ScheduleOptions;

    

    // The domain name is not required for all SMTP servers.

    SMTPSchedulingOptions.DomainName = DomainName;

    SMTPSchedulingOptions.Subject = Subject;

    

    // Populate the To and CC addresses.

    for(k=0;k<RecipientAddresses.length;k++)

        SMTPSchedulingOptions.ToAddresses.Add (RecipientAddresses[k]);

    for(k=0;k<CCAddresses.length;k++)

        SMTPSchedulingOptions.CCAddresses.Add (CCAddresses[k]);

    SMTPSchedulingOptions.Port = Port;

    SMTPSchedulingOptions.SenderAddress = SenderAddress;

    SMTPSchedulingOptions.ServerName = ServerName;

    

    // For the MimeType use the Report object's Mimetype property.

    SMTPSchedulingOptions.Attachments.Add(Report.MimeType,Attachment);

    SMTPSchedulingOptions.Message = Body;

    SMTPSchedulingOptions.SMTPAuthentication=Authentication;

    SMTPSchedulingOptions.SMTPUserName = UserName;

    SMTPSchedulingOptions.SMTPPassword = Password;

    

    // Copy the SMTP options into the report's scheduling info. This will cause the

    // instance to be sent via email after the report has been run.

    ScheduleInfo.Destination.SetFromPlugin (SMTP);

    

    //Tell the APS to schedule the report.

    IStore.Schedule (Reports);

}


function ScheduleToDisk(IStore,ReportId, FilePath)

/*

    Schedule the report and cause the instance to be copied to a local or network disk.

*/

{

    // Get the report.

    var Reports = IStore.Query("SELECT SI_ID, SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID="+ReportId);

    if (Reports.Count == 0)

    {    

        return;

    }

    var Report=Reports.Item(1);

    

    var ScheduleInfo ;

    //Create an interface to the scheduling options for the report.

    ScheduleInfo = Report.SchedulingInfo;

    // Run the report once.

    ScheduleInfo.Type = 0;

    // Run it right now.

    ScheduleInfo.RightNow = true;

    

    // Set the disk options.    

    var Disk;

    var DiskSchedulingOptions;

    // Get the Disk InfoObject from the APS.  Note that the SI_PARENTID will always be 29.

    Disk = IStore.Query("Select SI_DEST_SCHEDULEOPTIONS From CI_SYSTEMOBJECTS Where SI_PARENTID=29 and SI_NAME='CrystalEnterprise.DiskUnmanaged'").Item(1);

    // Get the actual DiskUnanaged object and its ScheduleOptions.

    DiskSchedulingOptions = Disk.PluginInterface("").ScheduleOptions;

    // Set the path.

   DiskSchedulingOptions.DestinationFiles.Add(FilePath);

    // Copy the disk options into the report's scheduling options. This will cause the

    // report's instance to be copied to the directory.

    ScheduleInfo.Destination.SetFromPlugin (Disk);

    

    //Tell the APS to schedule the report.

    IStore.Schedule (Reports);

}


function ScheduleToPrinter(PrinterName, Copies, FromPage, ToPage)

/*

    This function causes the instance of a report to be printed once it has finished

    running.

    

    NOTES

    To print all pages set FromPage and ToPage to zero.

*/


{

    // Get the report.

    var Reports = IStore.Query("SELECT SI_ID, SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID="+ReportId);

    if (Reports.Count == 0)

    {    

        return;

    }

    var Report=Reports.Item(1);

    

    var ScheduleInfo ;

    //Create an interface to the scheduling options for the report.

    ScheduleInfo = Report.SchedulingInfo;

    // Run the report once.

    ScheduleInfo.Type = 0;

    // Run it right now.

    ScheduleInfo.RightNow = true;

    

    // Get the printer options from the report plugin interface.  These can be found

    // under the Report object.

    PrinterOptions = Report.PluginInterface("").ReportPrinterOptions;

    

    // Set the printer options.

    PrinterOptions.Copies = Copies;

    // Enable the printer options otherwise the instance wont print.

    PrinterOptions.Enabled=true;

    PrinterOptions.FromPage = FromPage;

    PrinterOptions.ToPage = ToPage;

    

    // This name must be the actual name of the printer. Note that on Windows, in some cases,

    // the name displayed in the properties page of the printer is not the full printer name.

    PrinterOptions.PrinterName = PrinterName;

    

    //Tell the APS to schedule the report.

    IStore.Schedule (Reports);

}



function Main()

/*

    Depending on the destination that the user specified, get the options and schedule the

    report.

*/

{

    IStore = RetrieveIStore();

    if (IStore == null)

    {

        Response.Redirect("Start.csp");

        return;

    }

    // Since the Request object does not give back a string, cast it.

    ReportId = String(Request.QueryString.Item("ReportId"));

    Destination = String(Request.QueryString.Item("Destination"));

    switch(Destination)

    {

        case "FTP":

            ServerName = Request.Form.Item("ServerName");

            // In this case, since we want a number, we must first convert the item

            // to a string.

            Port = Number(String(Request.Form.Item("Port")));

            AccountName = Request.Form.Item("AccountName");

            UserName = Request.Form.Item("UserName");

            Password = Request.Form.Item("Password");

            FilePath = Request.Form.Item("FilePath");

            ScheduleToFTP(IStore,ReportId, ServerName,AccountName,UserName,Password,FilePath,Port);

            break;

        case "SMTP":

            ServerName = Request.Form.Item("ServerName");

            Port = Request.Form.Item("Port");

            DomainName = Request.Form.Item("DomainName");

            RecipientAddresses = String(Request.Form.Item("RecipientAddresses")).split(";");

            SenderAddress = Request.Form.Item("SenderAddress");

            Subject  = Request.Form.Item("Subject");

            CCAddresses = String(Request.Form.Item("CCAddresses")).split(";");

            Attachment=Request.Form.Item("Attachment");

            Body=Request.Form.Item("Body");

            Authentication = Number(Request.Form.Item("AuthenticationMethod"));

            UserName = Request.Form.Item("UserName");

            Password = Request.Form.Item("Password");

            ScheduleToSMTP(IStore,ReportId,DomainName,ServerName,Subject,SenderAddress,RecipientAddresses,Port, Attachment, CCAddresses, Body, Authentication, UserName, Password);

            break;

        case "Disk":

            FilePath = Request.Form.Item("FileName");

            ScheduleToDisk(IStore,ReportId,FilePath);

            break;

        case "Printer":

            PrinterName = Request.Form.Item("PrinterName");

            FromPage = Request.Form.Item("FromPage");

            ToPage = Request.Form.Item("ToPage");

            Copies = Request.Form.Item("Copies");

            ScheduleToPrinter(PrinterName,Copies,FromPage,ToPage);

            break;

    }

    Response.Write ("Scheduled");

    

}


Main();

%>

</body>

</html>





Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com