Identity Request Notification: How to set the dynamic subject of an email template depending on the approvalSet object

IdentityIQ 8.4

Hi,

I want to set a dynamic subject for the email template “LCM Requester Notification”.

To do this I’ve tried to set a variable into the of the template with a message depending on the status of the approvalSet item (Accepted or rejected).

<Body>
#set( $dynamicSubject= "my subject")
</Body>

When I use this: <Subject>$dynamicSubject</Subject>

The expression is not evaluated at all. I suspect that the code between the <Body></Body> tag is evaluated after what is between the <Subject></Subject> tag.

When I use a variable that is passed as an argument and set during the “Notify Requester” step, it works fine.

I think I need to create a new variable in the workflow, and in the “Notify Requester” step, do something like this :

#if ( $approvalSet )
            #if ( $approvalSet.hasApproved() )
                #foreach ($item in $approvalSet.approved)
                    #if ( $item.operation == "Create" )
                        #* This is an identity creation *#
                        #set( $dynamicSubject= "subject1" )
                    #else #* Modify identity  *#
                        #set( $dynamicSubject= "subject2" ) 
                    #end
                #end
            #end
            #if ( $approvalSet.hasRejected() )
                #foreach ($item in $approvalSet.rejected)
                    #if ( $item.operation == "Create" ) #* This is an identity creation *#
                        #set( $dynamicSubject= "subject 3" )
                    #else #* Modify identity  *#
                        #set( $dynamicSubject= "subject4" )
                    #end
                #end
            #end
            #if ( $approvalScheme == "none" )
                #foreach ($item in $approvalSet.items)
                    #if ( $item.operation == "Create" )
                        #* This is an identity creation *#
                        #set( $dynamicSubject= "Création du profil informatique pour $firstname $lastname ($typeContrat) effectuée" )
                    #else  #* Modify identity  *#
                        #set( $dynamicSubject= "subject 5" )
                    #end
                #end
            #end
        #end

But i’m not sure if this will work because in th “Notify Requester” step, the argument “approvalSet” is set by calling the following method: prepareApprovalSetForNotification

I don’t know what this method is doing but maybe if I try to use approvalSet in the script to set my “$dynamicSubject” argument, the object approvalSet won’t be correctly initialized…

Does anyone knows if there’s a simplier way to achieve what I want? Or how to be sure of the state of the approvalSet?

Thanks for your help

Hi @claborde,

As you suspected, in order to use the $dynamicSubject variable in the email subject, it must be previously passed as an argument in the workflow step. Since the <Body> section is evaluated after <Subject>, defining it there won’t work.

Instead of setting $dynamicSubject in the email template, you can handle this in the workflow itself. Here’s a structured way to do it:

  1. Ensure there is a process variable in the workflow for approvalSet – If it doesn’t already exist, create it. You don’t need to assign it a value initially, but make sure it’s marked as “Editable”.
  2. Add a step before “Notify Requester” – This should be a generic step where you select “Call Method” and choose prepareApprovalSetForNotification.
  3. Set the “Result Variable” of this step as approvalSet – This ensures the variable is properly initialized and accessible in the next step.
  4. Modify the “Notify Requester” step – Now that approvalSet is a global variable, use a script in this step to calculate dynamicSubject, adapting the logic from your post to beanshell.

By following these steps, your script should now work correctly, since approvalSet is properly initialized as a global variable before being used.

Let me know if you need any further clarification!

1 Like

Hi Ángel,

Thank you very much for your response. The solution I used was to get the approvalSet from the workflow, but there is a risk that it may be null in some cases. I’ll try your suggestion.

Here is the code I used to set a variable in the workflow:

import sailpoint.object.ApprovalSet;
import sailpoint.object.ApprovalItem;

String mailTemplateDynamic = "Statut non déterminé"; // Valeur par défaut

if (workflow != null) {

    ApprovalSet approvalSet = (ApprovalSet) workflow.get("approvalSet");

    if (approvalSet != null) {
        ...
        ...
        ...
      
} else {
    mailTemplateDynamic = "Erreur : Le workflow est null.";
}

// Stocker le résultat dans une variable du workflow pour être utilisée dans l’email
workflow.put("TemplateObjetDynamic", mailTemplateDynamic);

return mailTemplateDynamic 
1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.