Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Unable to schedule a report to email and print

I have been working on a task to both print and email a report to recipients whose email addresses are obtained at runtime. So far I am able to email the report as a PDF attachment, however, I am not able to get the report to print. I have three thoughts as to why the report is not printing.

1. The printer is in a subdomain under the domain where InfoView and the Enterprise server reside.

2. It is not possible to schedule a report for both an SMTP and print destination simultaneously.

3. The format is causing an issue in printing - the SDK API states "Printer is a report format specific destination and can only be used when the report object is a Crystal Report."

I have looked at the scheduled report in InfoView and can see that the print settings I am passing are correctly set for the scheduled instance. Does anyone know if there is a problem with trying to schedule printing and email at the same time, or if the report format must be .rpt?

Below is my code. Thank you for your time.

String query = "Select SI_ID, SI_NAME, SI_PROCESSINFO, SI_SCHEDULEINFO, SI_SCHEDULE_STATUS From CI_INFOOBJECTS Where SI_ID=" + reportId;
        IInfoObjects results = null;
        ISchedulingInfo schedulingInfo = null;
        
        try {        
           results = iStore.query(query);            
        } catch( SDKException sdke ){
           logger.error(sdke);
        }
        
        if( !results.isEmpty() ){
            
            // get the actual report object from collection and set scheduling information
            IInfoObject report = (IInfoObject)results.get(0);
            schedulingInfo = report.getSchedulingInfo();
            schedulingInfo.setType(CeScheduleType.ONCE);
            schedulingInfo.setRightNow(true);
            schedulingInfo.setRetriesAllowed(3);            
            
            try {
                Set<String> keys = destinations.keySet();
                Iterator i = keys.iterator();
                while( i.hasNext() ){
                
                    String dest = (String) i.next();
                    
                    if(dest.equals(CrystalDestinations.EMAIL)){
                        
                        // get the destination object and set it to SMTP plugin
                        List emailAddress = destinations.get(CrystalDestinations.EMAIL);
                        IDestination destinationObject = schedulingInfo.getDestination();
                        destinationObject.setName("CrystalEnterprise.SMTP");     
                            
                        IDestinationPlugin smtpPlugin = (IDestinationPlugin) iStore.query("SELECT * FROM CI_SYSTEMOBJECTS WHERE SI_PARENTID = 29 AND SI_NAME='CrystalEnterprise.SMTP'").get(0);
                        ISMTPOptions smtpOptions = (ISMTPOptions) smtpPlugin.getScheduleOptions();
                        smtpOptions.setDomainName( emailDomain );
                        smtpOptions.setServerName( smtpHost );
                        smtpOptions.setSMTPUserName( smtpUser );
                        smtpOptions.setSMTPPassword( smtpPass );
                        smtpOptions.setSubject( "Email for report " + report.getTitle() );
                        smtpOptions.setMessage( "This is the message body" );
                        smtpOptions.setSenderAddress( smtpUser + "@cdrh.fda.gov" );
                        smtpOptions.setSMTPAuthenticationType( ISMTPOptions.CeSMTPAuthentication.LOGIN );
                        
                        for(int j = 0; j < emailAddress.size(); j++ ){
                            smtpOptions.getToAddresses().add( emailAddress.get(j) );
                        }
                        
                        destinationObject.setFromPlugin( smtpPlugin );                                                                                
} else if ( dest.equals(CrystalDestinations.PRINT) ){
                        
                        List printers = destinations.get( CrystalDestinations.PRINT );                    
                        IReportPrinterOptions printerOptions = ((IReport)report).getReportPrinterOptions();
                        printerOptions.setCopies(1);
                        printerOptions.setEnabled(false);
                        printerOptions.setPrinterName( (String)printers.get(0) );                    
                        printerOptions.setPageLayout(IReportPrinterOptions.CeReportLayout.USE_SPECIFIED_PRINTER_SETTING);
                        
                    }                        
                                    
                }
                
                List reportPrompts = ((IReport)report).getReportParameters();
                for(int j = 0; j < reportPrompts.size(); j++){
                    
                    IReportParameter prompt = (IReportParameter) reportPrompts.get(j);                    
                    if(prompt.getParameterName().equals(mdrParamName)){
                    
                      IReportParameterSingleValue v = prompt.getCurrentValues().addSingleValue();
                      v.setValue(reportParameters.get(mdrParamName));
                      
                    } else if(prompt.getParameterName().equals(addressParamName)){
                    
                        IReportParameterSingleValue v = prompt.getCurrentValues().addSingleValue();
                        v.setValue(reportParameters.get(addressParamName));  
                    }
                    
                }
                
                IReportFormatOptions format = ( (IReport) report).getReportFormatOptions();
                format.setFormat(IReportFormatOptions.CeReportFormat.PDF);
                
                iStore.schedule( results );

Former Member
replied

Hi Jason,

Based on your code, I could not tell if you were scheduling a Crystal Report or a WebI document.

Regardless, what I would suggest is you try scheduling the report/document on InfoView.

Once you schedule it on InfoView, you can retrieve the instance on Query Builder (or through code) and compare the properties that are being set through InfoView and the one you set through your code.

This should indicate if you are missing some properies or have set some properties incorrectly.

Hope this helps.

Regards,

Dan

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question