# Call certification event template in rule

**URL:** <https://developer.sailpoint.com/discuss/t/call-certification-event-template-in-rule/14710>\
**Category:** IIQ Discussion and Questions\
**Tags:** identityiq, certifications\
**Created:** [July 20, 2023, 4:23am UTC](https://developer.sailpoint.com/discuss/t/call-certification-event-template-in-rule/14710 "2023-07-20T04:23:45Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Remold](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/remold/32/3275_2.png) [@Remold](https://developer.sailpoint.com/discuss/u/Remold)\
**Post date:** [July 20, 2023, 6:01pm UTC](https://developer.sailpoint.com/discuss/t/call-certification-event-template-in-rule/14710/6 "2023-07-20T18:01:50Z")

</div>

At one of our clients we use identity triggers for joiners, movers and leavers. Joiners and Leavers are to be processed as soon as possible while a mover is only processed it all role assignment, events are processed and also after the latests aggregations to have an clear view on what has been changed during the move processing/reassignment of business roles.

I have created an identity mover trigger to store the identityName in a custom object and run a task at the end of the daily processing to really start the certification.

The code to start the certification from the task is:

Initialize the certification aka create a new certification Template function:

```auto
    public CertificationDefinition initializeCertification (CertificationDefinition template, String name, String accReviewName, String accReviewShortName, Date date, String certOwner) throws GeneralException {
      if (log.isDebugEnabled()) log.debug("in initialize cert");

      //Cloning Certificate from existing template
      XMLObjectFactory instance = XMLObjectFactory.getInstance();
      CertificationDefinition newcert = (CertificationDefinition) instance.cloneWithoutId(template, (XMLReferenceResolver) context);

      newcert.setCreated(date);
      newcert.setModified(date);

      newcert.setName(name);
      newcert.setCertificationNameTemplate(name);
      newcert.setNameTemplate(accReviewName);
      newcert.setShortNameTemplate(accReviewShortName);

      Attributes attrMap = newcert.getAttributes();
      attrMap.put("owners", certOwner);
      newcert.setAttributes(attrMap);

      if (log.isDebugEnabled()) log.debug("newcert: " + newcert.toXml());
      context.saveObject(newcert);
      context.commitTransaction();
      context.attach(newcert);
      return newcert;
    }

```

Schedule the certification function:

```auto
    public void scheduleCertification (String certId, String name) throws Exception {
      if (log.isDebugEnabled()) log.debug("in schedule cert");
      TaskSchedule taskSchedule = new TaskSchedule();
      taskSchedule.setName(name);
      taskSchedule.setLauncher("spadmin");
      taskSchedule.setArgument("certificationDefinitionId", certId);
      taskSchedule.setArgument("executor", "Certification Manager");
      taskSchedule.setArgument("resultName", "Certification executor");

      TaskManager tm = new TaskManager(context);

      TaskResult tr = tm.runSync(taskSchedule, new HashMap());
      log.debug("taskresult: " + tr.calculateCompletionStatus().toString());
    }

```

To call the above functions with some data:

- moverName = the name of the identity
- Certification Definition to clone : Mover Certification

```auto
                Identity moverIdentity = context.getObjectByName(Identity.class, moverName);
                moverIdentityName = moverIdentity.getDisplayName();
                if (log.isDebugEnabled()) log.debug("Creating mover cert for "+ moverIdentityName);
                Date today = new Date();
                Calendar cal = Calendar.getInstance();
                cal.setTime(today); // don't forget this if date is arbitrary e.g. 03-14-1879
                int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); // 14
                int month = cal.get(Calendar.MONTH) + 1; // 3
                int year = cal.get(Calendar.YEAR); // 2018

                CertificationDefinition moverCertTemplate = context.getObject(CertificationDefinition.class, "Mover Certification");
                String moverCertName = "Certification for Mover " + moverIdentityName + " " + year + "-" + month + "-" + dayOfMonth;
                String accReviewName = "Certification for Mover " + moverIdentityName + " ("+ moverName + ") " + year + "-" + month + "-" + dayOfMonth;
                String accReviewShortName = "Certification for Mover " + moverName + " " + year + "-" + month + "-" + dayOfMonth;
                CertificationDefinition moverCertDef = initializeCertification(moverCertTemplate, moverCertName, accReviewName, accReviewShortName, today, "Mover certificeerders");
                List certIdentitiesList = new ArrayList();
                certIdentitiesList.add(moverName);
                moverCertDef.setIdentitiesToCertify(certIdentitiesList);

               scheduleCertification(moverCertName,"sched-"+moverCertName);

```

I hope this helps and provides creativity 😉

– Remold

---

_[View the full topic](https://developer.sailpoint.com/discuss/t/call-certification-event-template-in-rule/14710)._
