I have seen requirements where user have to send an email to user’s corporate email  address which includes the Hyperlink to a Report Instance. If you are looking for using the ISMTPOptions of BusinessObjects, it can only be used with an object present in the enterprise repository.
So when you set the SMTP options, in the mesage body, you would need to construct an open document url for the report instance you would want to send it to the user. However if you use the smtp settings from business objects, you would need to set that on any infoobject, thus that infoobject would be sent as an attachment with the email along with the message body you will specify.

If you do not want to send the report instance as an attachment and want to only send the hyperlink to report instance, you can achieve that by setting the setAttachmentsEnabled(boolean value) for ISMTPOptions as false.

A logic for this could be as follows.

1. Login to Enterprise
2. Get the InfoStore service.
3. Query for the main report to get the SI_LAST_SUCCESSFUL_INSTANCE_ID for the main report. This property has the instance id which was last successfull.
4. Again query the CMS repository to get the instance details and retrieve the instance CUID.
5. Pass this CUID to the open document url which will be added in the message body.
An example of the link would be
http://BIPW08R2:8080/BOE/OpenDocument/opendoc/openDocument.jsp?sIDType=CUID&iDocID=<instance CUID>
6. Get the Smtp destination plufin and set the smtp options for the pluging.

Below is the sample to send an open document url link for the last successfull report instance of a report to email destination.

Email Last Successful Report Instance as a Hyperlink

<%@ page import = “java.util.*,java.lang.Integer,
                   com.crystaldecisions.sdk.framework.*,
                   com.crystaldecisions.sdk.plugin.*,
                   com.crystaldecisions.sdk.plugin.desktop.report.*,
                   com.crystaldecisions.sdk.plugin.destination.smtp.*,
                   com.crystaldecisions.sdk.plugin.desktop.common.*,
                   com.crystaldecisions.sdk.exception.*,
                   com.crystaldecisions.sdk.occa.security.*,
       com.crystaldecisions.sdk.properties.*,
                   com.crystaldecisions.sdk.occa.infostore.*”
%>

<%
try {
 
    
  //Log in to the Enterprise.
  IEnterpriseSession enterpriseSession = CrystalEnterprise.getSessionMgr().logon( “administrator”, “Password”, “localhost:6400”, “secEnterprise”);
 
     //Obtain the InfoStore.
     IInfoStore infoStore = (IInfoStore)enterpriseSession.getService(“”, “InfoStore”);
    
     //Query for the report object in the CMS.  See the Enteprise Developer Reference guide for more information the Enterprise query language. 
     IInfoObjects oInfoObjects = (IInfoObjects)infoStore.query(“SELECT TOP 1 SI_ID,SI_NAME,SI_LAST_SUCCESSFUL_INSTANCE_ID ” +
                         “FROM CI_INFOOBJECTS ” +
                         “WHERE SI_KIND=’webi’ AND SI_INSTANCE_OBJECT=0 AND SI_NAME=’SMTPTest'” );

     if (oInfoObjects.size() > 0) {
     
      //Call local utility function to carry out the sending work. 
     IInfoObject infoObject = (IInfoObject)oInfoObjects.get(0);
     IProperties props=(IProperties)infoObject.properties();
     IProperty prop=(IProperty)props.getProperty(“SI_LAST_SUCCESSFUL_INSTANCE_ID”);
     String lastInstanceID=prop.getValue().toString();
    
     IInfoObjects lastSuccessInstance=infoStore.query(“SELECT TOP 1 * FROM CI_INFOOBJECTS WHERE SI_ID=”+lastInstanceID);
     IInfoObject lastSuccessInstanceInfoObject=null;
   if (lastSuccessInstance.size() > 0)
   {
lastSuccessInstanceInfoObject=(IInfoObject)lastSuccessInstance.get(0);
String lastSuccessInstanceInfoObjectCUID=lastSuccessInstanceInfoObject.getCUID();

//IDestinationPlugin destinationPlugin = getDestinationPlugin(infoStore, infoObject.getKind());
IDestinationPlugin destPlugin = (IDestinationPlugin)infoStore.query(“SELECT TOP 1 * ” +
                     “FROM CI_SYSTEMOBJECTS ” +
                     “WHERE SI_NAME=’CrystalEnterprise.Smtp'”).get(0);
           
    //Retrieve the Scheduling Options and cast it as ISMTPOptions
    //This interface is the one which allows us to set all of the required SMTP properties
    ISMTPOptions smtpOptions = (ISMTPOptions) destPlugin.getScheduleOptions();
    smtpOptions.setDomainName(“abc.com”);
    smtpOptions.setServerName(“localhost”);
    smtpOptions.setPort(25);
    //smtpOptions.setSMTPUserName(“smtpUsername”);
    //smtpOptions.setSMTPPassword(“smtpPassword”);
    smtpOptions.setSMTPAuthenticationType(ISMTPOptions.CeSMTPAuthentication.NONE);
    smtpOptions.setSubject(“Test”);
    smtpOptions.setMessage(“http://BIPW08R2:8080/BOE/OpenDocument/opendoc/openDocument.jsp?sIDType=CUID&iDocID=“+lastSuccessInstanceInfoObjectCUID);
    smtpOptions.setSenderAddress(“prithvi@xyz.com“);
//Remove the report from the attchment
smtpOptions.setAttachmentsEnabled(false);
           
    //Retrieve the list of SMTP recipients.
    List recipients = smtpOptions.getToAddresses();
    recipients.add(“prithvi@abc.com“);
ISendable obj = (ISendable)lastSuccessInstanceInfoObject;

IDestination destination = obj.getSendToDestination();
destination.setFromPlugin(destPlugin);

    //Send the InfoObjects.
    infoStore.sendTo(lastSuccessInstance);
          
      out.println(lastSuccessInstanceInfoObject.getTitle() + ” has been sent.”);
     
     }
     else {
      out.println(“Object ” + lastSuccessInstanceInfoObject.getTitle() + ” not found.”);
     }

    }
else
{
out.println(“Report Not Found!!!!!”);
}
}
    catch(SDKException sdkEx) {
  out.println(sdkEx);  
    }
    
%>

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply