Integration Email notifications with Workflow; How to?

To integrate the email notification method and the lifecycle event triggering the workflow, you can follow these steps:

  1. Create the Email Notification Method: You already have the code snippet for sending an email notification. Ensure this method is available in your class:
> public static void sendEmailNotification(String templateName, String toRecipient, Map<String, Object> variables) throws GeneralException {
>          SailPointContext context = SailPointFactory.getCurrentContext();
>          EmailTemplate emailTemplate = context.getObjectByName(EmailTemplate.class, templateName);
>          EmailOptions emailOptions = new EmailOptions();
>          emailOptions.setTo(toRecipient);
>          emailOptions.setVariables(variables);
>          context.sendEmailNotification(emailTemplate, emailOptions);
>      }

  1. Create the Lifecycle Event: Define a lifecycle event that will trigger when certain conditions are met. This event should be linked to your workflow.
  2. Access Event Object in Workflow: In your workflow, you will have access to the event object that contains the old and new values of the identity.
> Identity newIdentity = event.getNewObject();
> Identity previousIdentity = event.getOldObject();
  1. Trigger Email Notification in Workflow: Use the information from the event object to send an email notification. You can customize the email based on changes detected between the old and new identity objects.

Here is an example of how you can integrate these steps within a workflow:

>  public void workflowMethod(Event event) throws GeneralException {
>  Identity newIdentity = event.getNewObject();
>  Identity previousIdentity = event.getOldObject();
> 
>  String templateName = "YourEmailTemplate";
>  String toRecipient = newIdentity.getEmail();
>  Map<String, Object> variables = new HashMap<>();
>  variables.put("enddate_newValue", newIdentity.getStringAttribute("enddate"));
>  variables.put("endDate_oldValue", previousIdentity.getStringAttribute("enddate"));
>  
>  // Send the email notification
>  sendEmailNotification(templateName, toRecipient, variables);
> }

EmailTemplate example:

> <?xml version="1.0" encoding="UTF-8"?>
>  <!DOCTYPE EmailTemplate PUBLIC "sailpoint.dtd" "sailpoint.dtd">
>  <EmailTemplate name="YourEmailTemplate">
>      <Body>
>          &lt;html lang="de"&gt;
>          &lt;head&gt;
>          &lt;meta charset="UTF-8"/&gt;
>          &lt;style type="text/css"&gt;
>          @font-face{
>          font-family:'montserratregular';
>          font-display:auto;
>          font-weight:400;
>          font-style:normal}
>  
>          pre{
>          font-family: 'montserratregular',sans-serif;
>          }
>          &lt;/style&gt;
>          &lt;/head&gt;
>          &lt;body&gt;
>          &lt;pre&gt;
>          Hi
>  		Your text... $enddate_newValue
>  		.... $enddate_oldValue
>          Best regards,
>  		XYZ
>  
>  
>      </Body>
>      <Description>
>          Email Template for ...
>      </Description>
>      <Signature>
>          <Inputs>
>              <Argument name="enddate_newValue" type="String">
>                  <Description>Desc</Description>
>              </Argument>
>              <Argument name="enddate_oldValue" type="String">
>                  <Description>Desc.</Description>
>              </Argument>
>          <Argument name="anyAdditionalVariable" type="String">
>                  <Description>TDesc</Description>
>              </Argument>
>            </Inputs>
>      </Signature>
>      <Subject>Test text: $anyAdditionalVariable</Subject>
>  </EmailTemplate>
2 Likes