EmailTemplate Variable in Subject

Which IIQ version are you inquiring about?

Version 8.3

Please share any images or screenshots, if relevant.

img.png

Share all details related to your problem, including any error messages you may have received.

In a Email Template is it possible to use variables in the of the email?
I tried declaring a variable in the of the EmailTemplate using:

<![CDATA[	
	    #set($var=value)
...
]]>

and then used it in the as shown in the picture and the variable wasn’t recognized.

Hi @joaovrodrigues ,

Please find the below lines which is used to call something from context

>     #set($account=$spctx.getObjectByName($spTools.class.forName("sailpoint.object.Identity"),$acc))
1 Like

If possible could you please share the email template here or the error logs

1 Like

Here is the sample


`<Subject>Action Reminder: Review your Service Account by $spTools.formatDate($certification.getExpiration(), "dd-MMM-yyyy")</Subject>`
1 Like

@vishal_kejriwal1, your solution works for one of the variables I need to place in subject, but what do I do with a variable declared like this?

#if($currentMonth == "Jan" || $currentMonth == "Feb" || $currentMonth == "Mar")
		#set($quarter = "first quarter")
#elseif($currentMonth == "Abr" || $currentMonth == "May" || $currentMonth == "Jun") 
		#set($quarter = "second quarter")
#elseif($currentMonth == "Jul" || $currentMonth == "Aug" || $currentMonth == "Sep")
		#set($quarter = "third quarter")
#else
		#set($quarter = "forth quarter")  
#end
	

Check if you can pass this quarter variable as a argument itself to the email template and then directly use in subject . you can write this big code but then you need to alter the size of subject column in database table .

1 Like

How would I be able to pass that variable as an argument? Where would I place the input after declaring it as an argument?
image

@joaovrodrigues
Here is the sample -

Hope this helps.

1 Like

That part I had already managed to implement. My issue was centered in how I would be able to input the quarter value.

either you need to pass that value from the place wre you calling email to be sent . or if you don’t have placeholder you need to check for some workaround.

1 Like

In the following link it seems to be possible to use CDATA blocks in the Subject.
https://community.sailpoint.com/t5/Technical-White-Papers/Email-Template-Usage-and-Customization/ta-p/78164#toc-hId-1728847685

So I tried the following code:

<Subject>
  	<![CDATA[ 
		#set($currentMonth = $spTools.formatDate($certification.getActivated(),"MMM"))

		#if($currentMonth == "Jan" || $currentMonth == "Feb" || $currentMonth == "Mar")
			#set($quarter= "first quarter")
		#elseif($currentMonth == "Abr" || $currentMonth == "May" || $currentMonth == "Jun") 
			#set($quarter= "second quarter")
		#elseif($currentMonth == "Jul" || $currentMonth == "Aug" || $currentMonth == "Sep")
			#set($quarter= "third quarter")
		#else
			#set($quarter= "forth quarter")  
		#end

		<html>
			<body>
				This is the $quarter
			</body>
		</html>
	]]>
  </Subject>

And I still can’t get the quarter value.
Is it possible to use CDATA blocks in the Subject? If so, what am I doing wrong?

Tags doesn’t seems to be correct
Use the sample email Template to see where subject and body tag need to exist .

you can write this big code but then you need to alter the size of subject column in database table .
I think when you try to add the big subject it will not allow you to save email Template . I haven’t checked in 8+ version but in 7.3 I think size was less . You can check db table size for this column …

1 Like

Create a rule & move all the logic. Call the rule from the email template by passing the arguments.

Ex:

#set( $sailpointContext=$spTools.class.forName("sailpoint.api.SailPointFactory").getMethod("getFactory", null).invoke(null, null).getCurrentContext() ) 
    
#set( $quater = $sailpointContext.getObjectByName($spTools.class.forName("sailpoint.object.Rule"), "Rule_Get_Quater") )  
#set( $myarray = $sailpointContext.runRule($quater, $arguments) )

$arguments = this should be a map. In this case pass the certification object.
$myarray = result from the rule
1 Like


Size is 255 .
@joaovrodrigues

1 Like

Did you see the logs . I think it will say that it’s nit able to save rule because of size constraints.

1 Like

Thx 4 all the answers :blush:.
I tried to implement the rule as @vedeepak mentioned.
Rule Code:

...
   <Argument name="certification">
        <Description>
            The certification object.
        </Description>
        </Argument>
        </Inputs>
    </Signature>
        <Source>
            <![CDATA[
                // Library inclusions for BeanShell()
                import sailpoint.api.*;
                import sailpoint.object.*;
                import sailpoint.tools.*;
                //import java.util.*;
                import java.lang.*;
                //import java.text.*;
                import java.text.SimpleDateFormat;  
                import java.util.Date;

                SimpleDateFormat formatter = new SimpleDateFormat("MMM");
                Date currentMonth = certification.getActivated().getMonth();
                String trimestre;
                if(currentMonth >= 0 && currentMonth <= 2) trimestre = "primeiro trimestre";
                else if(currentMonth >= 3 && currentMonth <= 5) trimestre = "segundo trimestre";
                else if(currentMonth >= 6 && currentMonth <= 8) trimestre = "segundo trimestre";
                else if(currentMonth >= 9 && currentMonth <= 11) trimestre = "quarto trimestre";
                else {
                    log.error("Error with Month");
                    return null;
                }
                return trimestre;
            ]]>
        </Source>

EmailTemplate Code:

  <Subject>
  	<![CDATA[ 
		#set( $sailpointContext=$spTools.class.forName("sailpoint.api.SailPointFactory").getMethod("getFactory", null).invoke(null, null).getCurrentContext() ) 
		#set( $ruleArgs=$spTools.class.forName("java.util.HashMap").newInstance() )
		#set( $dummy = $ruleArgs.put( "certification", $certification))
		#set( $quarter= $sailpointContext.getObjectByName($spTools.class.forName("sailpoint.object.Rule"), "RuleName") )  
		#set( $myarray = $sailpointContext.runRule($quarter, $ruleArgs))

		<html>   	
			<p>$quarter<p/>
		</html>
	]]>
  </Subject>

Yet I still am facing the same error when importing to Sailpoint
image

PS. I tried importing without the set part of the EmailTemplate Code and there were no issues. Making me believe the issue lies somewhere in the set part of the code.

Did you see the logs ? . I think it will say that it’s not able to save rule because of size constraints.

1 Like

I would say check logs .

1 Like

I just checked the logs, there are none since the code can’t even be imported onto Sailpoint, I believe.
How would you recommend avoiding these size constraints, in the case that is the issue? The subject name on the code is only the quarter

This is what you are getting while importing

org.hibernate.exception.GenericJDBCException: could not execute statement

Check the full stack trace logs.