# EmailTemplate Variable in Subject

**URL:** <https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823>\
**Category:** IIQ Discussion and Questions\
**Tags:** rules, identityiq\
**Created:** [March 18, 2024, 2:46pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823 "2024-03-18T14:46:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 18, 2024, 2:46pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/1 "2024-03-18T14:46:23Z")

</div>

### Which IIQ version are you inquiring about?

Version 8.3

### Please share any images or screenshots, if relevant.

![img.png](https://global.discourse-cdn.com/sailpoint/original/2X/3/322fdeecbd61868bc96841ee864afcf7d1fe02bc.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:

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

```

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

---

<div class="post-metadata">

**Author:** ![kavindar\_sharma](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kavindar_sharma/32/4766_2.png) [@kavindar\_sharma](https://developer.sailpoint.com/discuss/u/kavindar_sharma)\
**Post date:** [March 18, 2024, 3:52pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/2 "2024-03-18T15:52:21Z")

</div>

Hi @joaovrodrigues ,

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

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

```

---

<div class="post-metadata">

**Author:** ![kavindar\_sharma](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kavindar_sharma/32/4766_2.png) [@kavindar\_sharma](https://developer.sailpoint.com/discuss/u/kavindar_sharma)\
**Post date:** [March 18, 2024, 3:53pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/3 "2024-03-18T15:53:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 18, 2024, 5:18pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/4 "2024-03-18T17:18:53Z")

</div>

Here is the sample

```auto

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

```

---

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 18, 2024, 6:04pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/5 "2024-03-18T18:04:05Z")

</div>

@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?

```auto
#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
	

```

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 18, 2024, 7:18pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/6 "2024-03-18T19:18:26Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 19, 2024, 10:49am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/7 "2024-03-19T10:49:25Z")

</div>

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](https://global.discourse-cdn.com/sailpoint/original/2X/7/71be8a8ac3c3e2f30f0d91897e20fba96f5c195b.png)

---

<div class="post-metadata">

**Author:** ![officialamitguptaa](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/officialamitguptaa/32/6624_2.png) [@officialamitguptaa](https://developer.sailpoint.com/discuss/u/officialamitguptaa)\
**Post date:** [March 19, 2024, 11:19am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/8 "2024-03-19T11:19:14Z")

</div>

@joaovrodrigues  
Here is the sample -

 ![image](https://global.discourse-cdn.com/sailpoint/original/2X/d/d6ed2fba819c5d1eef5a7dfaec481d9cc1f6069c.png)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 19, 2024, 2:41pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/9 "2024-03-19T14:41:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 19, 2024, 3:11pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/10 "2024-03-19T15:11:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 20, 2024, 11:53am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/11 "2024-03-20T11:53:35Z")

</div>

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](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:

```auto
<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?

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 20, 2024, 12:57pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/12 "2024-03-20T12:57:35Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![vedeepak](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vedeepak/32/14735_2.png) [@vedeepak](https://developer.sailpoint.com/discuss/u/vedeepak)\
**Post date:** [March 20, 2024, 3:07pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/14 "2024-03-20T15:07:32Z")

</div>

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

Ex:

```auto
#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

```

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 20, 2024, 5:48pm UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/15 "2024-03-20T17:48:23Z")

</div>

![image](https://global.discourse-cdn.com/sailpoint/original/2X/f/fc58271d54203a33be121a7b2ce886f566f09fda.png)  
Size is 255 .  
@joaovrodrigues

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 21, 2024, 11:30am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/17 "2024-03-21T11:30:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 21, 2024, 11:31am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/18 "2024-03-21T11:31:09Z")

</div>

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

```auto
...
   <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:

```auto
  <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](https://global.discourse-cdn.com/sailpoint/original/2X/5/568a089d35e6ec6984bb8184d8331a9640820dc0.png)

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.

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 21, 2024, 11:32am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/19 "2024-03-21T11:32:24Z")

</div>

> [@vishal\_kejriwal1](#):
>
> Did you see the logs . I think it will say that it’s nit able to save rule because of size constraints.

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

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 21, 2024, 11:33am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/20 "2024-03-21T11:33:35Z")

</div>

I would say check logs .

---

<div class="post-metadata">

**Author:** ![joaovrodrigues](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joaovrodrigues](https://developer.sailpoint.com/discuss/u/joaovrodrigues)\
**Post date:** [March 21, 2024, 11:37am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/21 "2024-03-21T11:37:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [March 21, 2024, 11:40am UTC](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823/22 "2024-03-21T11:40:21Z")

</div>

This is what you are getting while importing

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

Check the full stack trace logs.

[Next page](https://developer.sailpoint.com/discuss/t/emailtemplate-variable-in-subject/35823.md?page=2)
