Using an If statement in an email template

I’m wondering if the equality operator is just broken for this template. Let’s try some options to see if we can get string comparison to work.

#set($country = "Israel")
${country.equals("Israel")}
${country.compareTo("Israel")}

Looks like it works:

true
0

How about this:

#set($country = ${user.country})
${country.equals("Israel")}
${country.compareTo("Israel")}

That returns this:

image

One thing I found out last night, the user variables are NULL when using #if or #set.

For example:

#if( user.country )True#{else}False#end

Always evaluates to false. So outside of a conditional, the variable is not NULL, but inside a conditional, it is NULL.

What if you add the $.

#if( $user.country ) True#{else}False#end

Sorry that was a typo. I had included the $ in testing. It evaluated to false

Instead of returning False, try returning $user.country.

Input:

The value of user.country is $user.country
#if($user.country)True#{else}$user.country#end

Output:

The value of user.country is Israel
Israel

I’m all out of ideas at this point. I created an engineering ticket to get this looked at. For my reference, the ticket number is IDNETN-7455.

Well thank you so much for your help Colin you’ve been a big help, I really appreciate it. I created a customer support ticket #(160280) yesterday so hopefully someone can get this figured out.

@jwinans12

Maybe try getting the identity context following this compass post.

Relevant code is as follows:

#set($spctx=$spTools.class.forName("sailpoint.api.SailPointFactory").getMethod("getFactory", null).invoke(null, null).getCurrentContext())

#set($identity=$spctx.getObjectByName($spTools.class.forName("sailpoint.object.Identity"), "spadmin"))

Identity Name from context: ${identity.name}

Hey @colin_mckibben and @jwinans12, I actually tested the Certification email template with this logic myself, and it works just fine for me.

@jwinans12 will you try a “contains” mehod Maybe that will help (FYI-you can only apply it to a variable, not a value within an array or object, so we will have to use the set function):

#set($userband=${user.band})#if($userband.contains('700'))SUCCESS#{else}FAIL#end

Also, you can try the “equals” method as well, but just like “contains,” it needs to be a single variable and cannot be used on an object or array; this is why you received the error previously.

#set($userband=${user.band})#if($userband.equals('700'))SUCCESS#{else}FAIL#end

You can even attempt the startsWith method:

#set($userband=${user.band})#if($userband.startsWith('700'))SUCCESS#{else}FAIL#end

All of these options work for me in successful evaluations.

Just so you both know as well, I am applying this logic myself to ${user.department}, so I know that the template is able to reference other attributes for the recipient other than “name.” I even created a “band” attribute for my identity and set the value to 700. All of this logic works for ${user.band} myself.

One final note @jwinans12 – I do not know if I was doing something wrong before or if something changed, but I am able to get the appropriate values with the Test Email function. Because it’s being sent to me by default (I have all emails going to myself in the Sandbox environment through the Email Config option), it is pulling my Identity data. As long as you have an identity with your email address populated, it should be able to pull your information, so testing is a lot easier.

Hello @colin_mckibben and @jwinans12,

I’m the triage engineer who picked up Colin’s ETN ticket. I wanted to let you know that I was able to reproduce this issue, and escalated to the team that handles development on the access request email tempate.

I’ll keep you posted with our progress.

Thanks!
Rich

1 Like

Hey @brennenscott,

Using the test email does work as intended, for example, I put in the template:

The value of user.displayName is $user.displayName
#if($user.displayName == ‘Justin Winans’)Success#{else}Fail#end

Resulting in:

The value of user.displayName is Justin Winans
Success

However, if I set up a certification campaign and assign it to myself, the email I receive is:

The value of user.displayName is Justin Winans
Fail

It’s very odd.

@jwinans12 wow, that’s so strange. I definitely didn’t try testing through the actual certification campaign, so that is my fault. Looks like it’s gotta be in the hands of the professionals now.

Thanks for the opportunity to discuss and troubleshoot–I definitely learned some useful information here.

1 Like

Hello @brennenscott, @jwinans12,

For email templates, when the initial message construction starts, the variable $user is not yet set, as the substitution phase occurs after evaluating the IF/ELSE logic blocks. So, at the point where the comparisons are being made, the $user variable doesn’t contain any data, and this is what causes the non-matching behavior you are seeing. This explains why the test email works, because the $user variable DOES exist when it is processed that way (the test uses the current user info).

To correct this, we will need to rework how the templates get processed, which will take some time (in other words, not a quick fix, as the work will need to be scoped, assigned, worked, and tested). I’ve created a development ticket for the appropriate team and will be monitoring their progress.

I don’t have any timeline yet when this will be fixed, but I’ll update this thread as I have additional information. Thanks for your patience, and please feel free to ask any questions you have.

Thanks, Rich

1 Like

Good morning @brennenscott, @jwinans12,

Our developers have released an update to this functionality and we believe it should work now. Could you please let me know if you are still seeing any issues?

Thanks! Rich

1 Like

I looks like the issue is still not fixed. When I put this in the template:
image

If I click the “Test Email” button I correctly receive an email response of:
image

However, if I actually create a certification and assign it to myself I get a different response:
image

I did not change anything in the email template.

Hello @jwinans12 ,

My apologies for missing your reply. It turns out that this was not a simple thing to fix, and it is still being actively worked on. I will be monitoring that work, and will reach out as soon as it has been completed and is available in customer tenants.

Thanks! Rich