cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to update or remove notification emails using the Java SDK

AnalystMark
Discoverer
847

I have several hundred reports with notification emails I'd like to clean up using the Java SDK. I've been able to update the first email listed. However, I can’t figure out how to remove the subsequent email addresses. Also, is it possible to just turn off the notifications in the default settings (using the SDK)?

Version: SAP 4.3 SP4

CMC > Folders > Report > Default Settings > Notification

SAP43 Success Emails.png

Query Builder

SELECT SI_ID,
       SI_NAME,
       SI_PROGID,
       SI_INSTANCE,
       SI_SCHEDULEINFO.SI_NOTIFICATION
FROM CI_INFOOBJECTS
WHERE SI_ID IN (8822)

SAP43 Query Builder.png

// Connect to the SAP CMS
BCM.initializeSAPJCE();
IEnterpriseSession eSession = null;
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
eSession = sessionMgr.logon(user,password,cmsName,cmsAuthType);

// Initialize Infostore objects
IInfoStore iStore = null;
IInfoObjects oInfoObjects = null;
IInfoObject oInfoObject = null;

// Query Builder query
iStore = (IInfoStore)eSession.getService("InfoStore");
oInfoObjects = (IInfoObjects)iStore.query("SELECT TOP 1000000 "
	+ "SI_ID, SI_NAME, SI_SCHEDULEINFO.SI_NOTIFICATION "
	+ "FROM CI_INFOOBJECTS WHERE SI_ID IN (8822)");
	
System.out.println("Number of reports: " + oInfoObjects.size());

if (oInfoObjects.size() > 0) {
	for (int i =0; i < oInfoObjects.size(); i++) {
		String SI_ID = "";
		String SI_NAME = "";
		try {
			oInfoObject = (IInfoObject) oInfoObjects.get(i);
		
			SI_ID = oInfoObject.properties().getProperty("SI_ID").getValue().toString();
			SI_NAME = oInfoObject.properties().getProperty("SI_NAME").getValue().toString();
			System.out.println(SI_ID + ": " + SI_NAME);
		
			ISchedulingInfo schedulingInfo = (ISchedulingInfo)oInfoObject.getSchedulingInfo();
			IProperties schedulingProperties = (IProperties)schedulingInfo.properties();
			System.out.println("Scheduling Info > Properties");
			
			IProperties SI_NOTIFICATION = (IProperties)schedulingProperties.getProperties("SI_NOTIFICATION");
			IProperties SI_DESTINATION_SUCCESS = (IProperties)SI_NOTIFICATION.getProperties("SI_DESTINATION_SUCCESS");
			IProperties successNotificationOne = (IProperties)SI_DESTINATION_SUCCESS.getProperties("1");
			IProperties SI_DEST_SCHEDULEOPTIONS = (IProperties)successNotificationOne.getProperties("SI_DEST_SCHEDULEOPTIONS");
			IProperties SI_MAIL_ADDRESSES = (IProperties)SI_DEST_SCHEDULEOPTIONS.getProperties("SI_MAIL_ADDRESSES");
			IProperty emailOne = (IProperty)SI_MAIL_ADDRESSES.getProperty("1");
			System.out.println("SI_NOTIFICATION > SI_DESTINATION_SUCCESS > 1 > SI_DEST_SCHEDULEOPTIONS > SI_MAIL_ADDRESSES > 1");
			
			emailOne.setValue("UpdateEmail@example.com");
			iStore.commit(oInfoObjects);
			
			IProperty emailTwo = (IProperty)SI_MAIL_ADDRESSES.getProperty("2");
			System.out.println("SI_NOTIFICATION > SI_DESTINATION_SUCCESS > 1 > SI_DEST_SCHEDULEOPTIONS > SI_MAIL_ADDRESSES > 2");
			
			// Tried these and they broke the report in the CMC
			//emailTwo.setValue("");
			//emailTwo.setValue(null);
			//SI_MAIL_ADDRESSES.remove("2");
			//SI_DESTINATION_SUCCESS.remove("1");
			//iStore.commit(oInfoObjects);
			
		} catch (NullPointerException e) {
			System.out.println("Try Catch Error");
		}
	}
}

eSession.logoff();

 

Accepted Solutions (1)

Accepted Solutions (1)

MichaelGrackin
Contributor

The following is code I have used to clear notifications on a document.  Hope this helps.

private static boolean clearNotifications(IInfoObject argTheDocument, String argDestinationType) {
Explore.actionLogger("clearNotifications: " + argDestinationType,1);
try {
ISchedulingInfo docSchedulingInfo = argTheDocument.getSchedulingInfo();
INotifications theScheduleNotifications = docSchedulingInfo.getNotifications();
IDestinations theDestinations = null;
switch (argDestinationType) {
case "SuccessNotifications" : {
theDestinations = theScheduleNotifications.getDestinationsOnSuccess();
theDestinations.clear();
break;
}
case "FailureNotifications" : {
theDestinations = theScheduleNotifications.getDestinationsOnFailure();
theDestinations.clear();
break;
}
}
return true;
} catch (SDKException e) {
return false;
}
}

 

AnalystMark
Discoverer
0 Likes
Thanks Michael, that helped point me in the right direction. I was able to clear both the success and failure notifications.
AnalystMark
Discoverer

Here's what I ended up using:

try {
	oInfoObject = (IInfoObject) oInfoObjects.get(i);

	SI_ID = oInfoObject.properties().getProperty("SI_ID").getValue().toString();
	SI_NAME = oInfoObject.properties().getProperty("SI_NAME").getValue().toString();
	System.out.println(SI_ID + ": " + SI_NAME);

	ISchedulingInfo schedulingInfo = (ISchedulingInfo)oInfoObject.getSchedulingInfo();
	INotifications schedulingNotifications = schedulingInfo.getNotifications();
	
	IDestinations notificationDestinations = null;
	
	try {
		notificationDestinations = schedulingNotifications.getDestinationsOnSuccess();
		notificationDestinations.clear();
		iStore.commit(oInfoObjects);
		System.out.println("Success Notifications Cleared");
	} catch (NullPointerException e) {
		System.out.println("Success Notification Exception");
	}
	
	try {
		notificationDestinations = schedulingNotifications.getDestinationsOnFailure();
		notificationDestinations.clear();
		iStore.commit(oInfoObjects);
		System.out.println("Failure Notifications Cleared");
	} catch (NullPointerException e) {
		System.out.println("Failure Notification Exception");
	}
} catch (NullPointerException e) {
	System.out.println("No info");
}

 

Answers (0)