Dynamic Subject in Email Template

I want the subject line of an approval notification email to show “SECRET APPROVAL REQUIRED” when the requestee’s custom attribute (e.g., employeeType) is set to “NPAUser”. Otherwise, it should default to “APPROVAL REQUIRED”.

I tried using this logic inside the Subject tag like this:

<Subject>
#set ($subjectLine = "APPROVAL REQUIRED")
#if ($requestee.getAttribute("employeeType") == "NPAUser")
  #set ($subjectLine = "SECRET APPROVAL REQUIRED")
#end
$subjectLine
</Subject>

This works fine in the Body, but while saving the template, I get a runtime error, possibly related to subject length or invalid content for the XML element.

  1. Is there a safe and supported way to use conditional logic inside Subject without triggering validation or length issues?
  2. Can we declare shared variables once and use them across both Subject and Body?
  3. Are there any best practices or examples for handling short dynamic subject lines in SailPoint email templates?

Any advice or working patterns would be greatly appreciated!

Hi Pratik
instead of using multi-line logic, did you try ternary expression in the <Subject> tag? Something like:

<Subject>${requestee.getAttribute("employeeType") == "NPAUser" ? "SECRET APPROVAL REQUIRED" : "APPROVAL REQUIRED"}</Subject>

Hi @saiprashanth88
Its not accepting ternary operator in subject tag.
Email template is not getting triggered.

Error sending email: Reason: Encountered &quot; == &quot;NPAUser&quot; ? &quot;SECRET APPROVAL REQUIRED&quot; : &quot;APPROVAL REQUIRED&quot;} &quot; at anonymous[line 1, column 35]
Was expecting one of:
&quot;[&quot; …
&quot;|&quot; …
&quot;}&quot; …
&quot;}&quot; …

@pctripathi try

<Subject>Approval Type #if ($requestee.getAttribute("employeeType") == "NPAUser") "SECRET APPROVAL REQUIRED" #else "APPROVAL REQUIRED" #end</Subject>

it works like below

#if(condition)
     value
#elseif(condition)
    value
#end

Or

#if(condition)
     value
#else
    value
#end

Let us know if that works

Hi Pratik,

SailPoint allow max 256 characters in the subject line, if you are uabble to achive the business requirement with this, you can pass the subject line from wherever you are calling the Email, you can pass that subject line as one of the argument to the email template

Hi @pravin_ranjan
I am using it but its skipping to else condition. But the same condition is working inside body.

Hi @pctripathi ,

Try this

<Subject> #if($requestee.getAttribute("employeeType") =="NPAUser") SECRET APPROVAL #else APPROVAL #end REQUIRED </Subject>

Hi @Arun-Kumar
Is it possible that subject is not capable of doing this. It can only populate predefined values inside sailpoint?
Because this same approach I am using inside body and getting correct result but here under subject when I am adding this logic then its skipping to else condition.

try to just add $requestee in subject to see if you are getting this object in Subject. also can u send me latest code that you are testing ? may be you can pass employeeType from workflow else you need to get object in email from name or Id whatever you have.

<Subject>Approval Type #if ($employeeType == "NPAUser") "SECRET APPROVAL REQUIRED" #else "APPROVAL REQUIRED" #end</Subject>

1 Like

Hi @pravin_ranjan
Just checked $requestee inside subject tag as well as body tag.
In body tag it displayed data but in Subject tag it just populated $requestee as output

hi @pravin_ranjan
Thanks. I tried myself. declaired an arg in workflow and called it in my email template. It worked.

1 Like