How to disable work item reminders/escalations in a task?
This task was developed to remove certifier from delegation reminders. For example, in a manager certification campaign with access reviews delegated to his/her direct reports, reminders would go to both the manager and direct reports. In the case of manager not wanting the reminders, run this task to disable it.
Import this rule and create a "Run Rule" task that points to the rule. In the rule config of the task, provide this as input argument: CertificationGroupID,ff808081552c2b0d01553143c01f07f2
The CertificationGroup id can be found in Debug.
If you want to integrate this to be part of the certification campaign, you can put the logic below in a workflow and schedule it in your certification's Active Period Enter Rule (Rule type="CertificationPhaseChange"). Please read this white paper for how to Scheduling a Workflow to run in the future from BeanShell / Rule code.
- <?xml version='1.0' encoding='UTF-8'?>
- <!DOCTYPE Rule PUBLIC "sailpoint.dtd""sailpoint.dtd">
- <Rule language="beanshell" name="Disable Reminder Rule">
- <Source>
- <![CDATA[
- import org.apache.log4j.Logger;
- import org.apache.log4j.Level;
- import sailpoint.api.ObjectUtil;
- import sailpoint.object.Identity;
- import sailpoint.object.Certification;
- import sailpoint.object.CertificationGroup;
- import sailpoint.object.CertificationEntity;
- import sailpoint.object.CertificationDelegation;
- import sailpoint.object.AbstractCertificationItem;
- import sailpoint.object.NotificationConfig;
- import sailpoint.object.NotificationConfig.IConfig;
- import sailpoint.object.WorkItem;
- import sailpoint.object.Filter;
- import sailpoint.object.QueryOptions;
- import sailpoint.tools.Util;
- Logger log = Logger.getLogger("sailpoint.services.rule.myrule");
- log.setLevel(Level.DEBUG);
- log.debug("myrule" + config.get("CertificationGroupID"));
- QueryOptions ops = new QueryOptions();
- ops.add( Filter.eq( "certificationGroups.id", CertificationGroupID));
- Iterator iterator = context.search( Certification.class, ops );
- // Iterate through access reviews
- while (iterator != null && iterator.hasNext()) {
- Certification cert = (Certification) iterator.next();
- log.debug("Looking into cert: " + cert.getName());
- List certifiers = cert.getCertifiers();
- if (certifiers != null) {
- // The certifying manager is always the first (0) certifier.
- String certifier = certifiers.get(0);
- List certWIs = cert.getWorkItems();
- if (certWIs != null) {
- // Iterate through the associated work items.
- for (WorkItem wi : certWIs) {
- Identity notifyOwner = (Identity) wi.getNotificationOwner(context);
- // Check the current work item to see if it is meant for the certifying manager
- if ((notifyOwner != null) && notifyOwner.getName().equals(certifier)) {
- NotificationConfig nConfig = wi.getNotificationConfig();
- if ((nConfig != null) && (nConfig.getConfigs() != null)) {
- List subConfigs = nConfig.getConfigs();
- Iterator sConfigsIter = subConfigs.iterator();
- while (sConfigsIter.hasNext()) {
- NotificationConfig.IConfig iConfig = sConfigsIter.next();
- // Find the target email template
- if (iConfig.getEmailTemplateName().equals("my template name") && iConfig.isEnabled()) {
- if (!ObjectUtil.isLockedById(context, WorkItem.class, wi.getId())) {
- try {
- // Mark the target email template as disabled for the work item that belongs to the certifying manager
- iConfig.setEnabled(false);
- // Change the next wakeup date to next reminder if there is any
- if( sConfigsIter.hasNext() ) {
- NotificationConfig.IConfig nextIConfig = sConfigsIter.next();
- long launchTime = wi.getWakeUpDate().getTime() + ( nextIConfig.getMillis() - iConfig.getMillis() );
- wi.setWakeUpDate(new Date(launchTime));
- }
- context.saveObject(wi);
- context.saveObject(cert);
- } finally {
- context.commitTransaction();
- log.debug( "Successfully disabled " + certifier );
- }
- } // end lock work item
- }// end email template name match
- } // end subConfigs loop
- } // end config null check
- } // end notifyOwner null check
- } // end work item loop
- } // end certWIs null check
- } // end certifiers null check
- } // end iterator
- Util.flushIterator(iterator);
- return"Success";
- ]]>
- </Source>
- </Rule>