Skip to Content
0

Update Destination details of email and mail alert notification for recurring schedules

May 04 at 11:48 AM

95

avatar image
Former Member

HI,

We have new requirement where the domain of the user email is getting change from @abc123.com to @abc.com. we have 400 recurring schedules in the production which has email as the destination. We also have few 100 schedules which has the notification alert enabled for success and failure status, we also need to change the email address.

I have Java sdk knowledge, but i am struggling to find a right query in place as this seem to be a big task.

please let us know the java sdk script or idea to this.

Regards

MK

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Bharath B N
May 07 at 09:27 AM
3

Check for "Set destination to SMTP":

https://help.sap.com/viewer/0225aa3e7b4b4b17b2d4a882e6f2de96/4.2.5/en-US/45a694d86e041014910aba7db0e91070.html

sample code:

void configureDestinationToSMTP(IEnterpriseSession enterpriseSession) throws SDKException

    {

      IInfoStore infostore = (IInfoStore)enterpriseSession.getService("InfoStore");  

      IInfoObjects reccuringInfoObjects = infostore.query("Select * from CI_INFOOBJECTS where SI_INSTANCE = 1 and SI_SCHEDULE_STATUS = 9");

      IInfoObject infoObject = (IInfoObject)reccuringInfoObjects.get(0);

     

      ISchedulingInfo schedulingInfo = infoObject.getSchedulingInfo();

      IDestinations destinations = schedulingInfo.getDestinations();

      String pluginType = "CrystalEnterprise.Smtp";

      Iterator destinationsIter = destinations.iterator();

      IDestination destination=null;

      while (destinationsIter.hasNext())

      {

          destination = (IDestination) destinationsIter.next();

          if (pluginType.equals(destination.getName()))

              break;

      }

      

      IInfoObjects smtpInfoObjects = infostore.query("Select SI_DEST_SCHEDULEOPTIONS, SI_PROGID From CI_SYSTEMOBJECTS Where SI_NAME = 'CrystalEnterprise.Smtp'");

      IInfoObject smtpinfoObject = (IInfoObject)smtpInfoObjects.get(0);

      IDestinationPlugin destinationPlugin = (IDestinationPlugin)smtpinfoObject;

      ISMTP smtp = (ISMTP)destinationPlugin;

           

      ISMTPOptions smtpOptions = (ISMTPOptions)smtp.getScheduleOptions();

      smtpOptions.setDomainName("domain");

      smtpOptions.setServerName("servername");

      smtpOptions.setPort(Integer.parseInt("25"));

      smtpOptions.setSMTPAuthenticationType(ISMTPOptions.CeSMTPAuthentication.LOGIN);

      smtpOptions.setSMTPUserName("username");

      smtpOptions.setSMTPPassword("password");

      smtpOptions.setSubject("Email subject");

      smtpOptions.setMessage("This is the email message.");

       

      

      //update TO address here

      List toAddresses = smtpOptions.getToAddresses();

      toAddresses.add("user1@emaildomain.com");

      toAddresses.add("user2@emaildomain.com");

      

      //update CC address here

      List ccAddresses = smtpOptions.getCCAddresses();

      ccAddresses.add("user1@emaildomain.com");

      ccAddresses.add("user2@emaildomain.com");

      

      destination.setFromPlugin(destinationPlugin);

      infoObject.save();

            

    }
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,

Thank you so much .

However, can you please help me in doing the same for Notifications, where we setup the success and failure notification, my requirement is to modify the email addresses of the notification as well.

I came across this thing called INotification but not enough sample codes on that.

Regards

MK

0
Bharath B N
May 09 at 06:19 AM
3

https://help.sap.com/viewer/0225aa3e7b4b4b17b2d4a882e6f2de96/4.2.5/en-US/45a29be16e041014910aba7db0e91070.html

Sample code for notification (not tested):

public void triggerNotification(IInfoObject job) throws SDKException {
              try {
                  ISchedulingInfo info = job.getSchedulingInfo();
                  INotifications notifications = info.getNotifications();
                 boolean notificationSuccess = (notifications != null && 
                          !notifications.getDestinationsOnSuccess().isEmpty() && statistics.getError() == 0);
                  boolean notificationFailure = (notifications != null && 
                         !notifications.getDestinationsOnFailure().isEmpty() && statistics.getError() > 0);
                  
                  if (!notificationSuccess && !notificationFailure) {
                      return;
               }
                 String subject = (notificationSuccess)? LogMessageUtility.getInstance().
                         getMessage("IDS_JOB_NOTIFICATION_SUCCESS", this.job.getTitle()) : 
             LogMessageUtility.getInstance().getMessage("IDS_JOB_NOTIFICATION_FAILURE", this.job.getTitle()); 
                 
                 String message = createMessage();
               IDestinations destinations = (notificationSuccess)? notifications.getDestinationsOnSuccess() : 
                     notifications.getDestinationsOnFailure();
                 for (Object obj : destinations) {
                     IDestination dest = (IDestination) obj;
                     if (!"CrystalEnterprise.Smtp".equals(dest.getName())) {
                         continue;
                     }
              IProperties props = dest.properties().getProperties(PropertyIDs.SI_DEST_SCHEDULEOPTIONS, true);
                     props.setProperty(SI_MAIL_SUBJECT, subject);
                     props.setProperty(SI_MAIL_MESSAGE, message);//set here properties
                 }
                 job.save();
             } catch (SDKException e) {
                 throw e;
             }
             
         }
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Bharath,

Thanks for this extended help.

My question is that i can able to get the code of getting the success and failure address, all i can see is only the getfunctions for to mail, bcc, sender mail, cc, only for the sender mail i can see the function called setsenderaddressl for all other i was not able to do so. See my below code, i can able to modify only the senderAddress

if(webiobject.getSchedulingInfo().getNotifications().getDestinationsOnSuccess().size() !=0)

{

Dest_Succ = (IDestination) webiobject.getSchedulingInfo().getNotifications().getDestinationsOnSuccess().get(0);

if (! Dest_Succ.isSystemDefaultOptionsUsed()) { SmtpPlugin = (IDestinationPlugin) boInfoStore.query("Select Top 1* from CI_SYSTEMOBJECTS Where SI_NAME = 'CrystalEnterprise.SMTP'").get(0);

Dest_Succ.copyToPlugin(SmtpPlugin); ISMTPOptions SmtpOptions = (ISMTPOptions)

SmtpPlugin.getScheduleOptions(); SmtpOptions.getSenderAddress(); SmtpOptions.set; System.out.println("Sucess Sender Email:"+SmtpOptions.getSenderAddress());

String x=SmtpOptions.getSenderAddress();

String y=x.replaceAll("(?i)xyz", "abcdefg");

System.out.print("the value after replacement "+y);

SmtpOptions.setSenderAddress(y);

Dest_Succ.setFromPlugin(SmtpPlugin);

boInfoStore.commit(boInfoObjects);

Dest_Succ.setFromPlugin(SmtpPlugin);

}

}


Many thanks

MK

1

how about this?

//updateTO address here

      List toAddresses = smtpOptions.getToAddresses();

      toAddresses.add("user1@emaildomain.com");

      toAddresses.add("user2@emaildomain.com");

//update CC address here

      List ccAddresses = smtpOptions.getCCAddresses();

      ccAddresses.add("user1@emaildomain.com");

      ccAddresses.add("user2@emaildomain.com");
0
Dell Stinnett-Christy May 04 at 02:05 PM
2

You'll run a query to get the recurring schedules - Select * from CI_INFOOBJECTS where SI_INSTANCE = 1 and SI_SCHEDULE_STATUS = 9

For each IInfoObject in the list, you'll call .getSchedulingInfo() to get the ISchedulingInfo. Then you'll call .getDestinations() and call getName() for each IDestination in the list. If the name is "CrystalEnterprise.Smtp", this is a schedule to email. You'll then have to go through the properties of the IDestination to update SI_MAIL_ADDRESSES, SI_MAIL_CC, and SI_MAIL_BCC to update the addresses. When you're finished updating the addresses, you'll call .save() on the IInfoObject to save them to the CMS.

-Delll

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,

Thank you so much .

However, can you please help me in doing the same for Notifications, where we setup the success and failure notification, my requirement is to modify the email addresses of the notification as well.

I came across this thing called INotification but not enough sample codes on that.

Regards

MK

0

I haven't specifically worked with notifications, but here's what I would do:

1. Run a Query-Builder query that pulls all of the properties for one or more schedules that have notifications.

2. Look at the properties of the schedule - probably in the Scheduling Info - to find which ones contain notification information.

3. In your code, access the IProperties bag where you can get/set this information for the notifications.

4. Be sure to call .save() when you're finished updating each schedule.

-Dell

1
Bharath B N
May 09 at 05:13 AM
2
Share
10 |10000 characters needed characters left characters exceeded