Saviynt unveils its cutting-edge Intelligence Suite products to revolutionize Identity Security!
Click HERE to see how Saviynt Intelligence is transforming the industry.
Saviynt Copilot Icon

Conditional Content within Email Template

mgra
New Contributor III
New Contributor III

Hello,

I'm trying to define a condition with the following values below on the body of email and it doesn't trigger an email notification. 

<% if (${user.customproperty11} == null)

print "QR Code not found, please contact Support"

else

<img src="https://xxxxxxx/chart?cht=qr&chs=350x350&chl=${user.customproperty11}">

%>

However, when I changed the operator <% %> into {% %} it then triggers an email but it doesn't read the html code as conditional statement instead it displays below output. 

graceandrade_0-1664962872104.png

26 REPLIES 26

rushikeshvartak
All-Star
All-Star

<% if (user.customproperty11 == null) print "QR Code not found, please contact Support" else "<img src=\"https://xxxxxxx/chart?cht=qr&chs=350x350&chl=${user.customproperty11}\">"%>

try simple logic without adding img tag in else, You need to escape " in QR URL

<% if (user.customproperty11 == null) print "QR Code not found, please contact Support" else "QR"%>


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

I've tried what you've suggested but it doesn't send an email. Also, I don't see anything from the logs that's blocking it.

print ${user.custompropery11}

it might be blank & not null


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

Still not working. 

Turn off html content flag n try,

Which email trigger are you attaching email template ?


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

No luck, it doesn't send an email. I'm trying to attach the email to a user update rule and even try creating a separate email for analytic. If I removed the if else condition, it then sends an email. So I'm guessing that problem is the conditional statement. 

Validate variables exposed in email template using below script add in email body.

 

Its possible user object is not exposed.

${this.binding.variables.each {k,v -> println "$k = $v" + "<" + "br" + ">"}}


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

I tried this email for testing purposes. but didn't trigger an email. 

graceandrade_0-1665028699295.png

 

Remove all logics related to analyticsdata from subject & email body & try


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

I have removed the conditional statement and just left the below variables. It then sends an email. But when I added back the if else statement it doesn't send the email again. Is the conditional statement really working on the email template?

${this.binding.variables.each {k,v -> println "$k = $v" + "<" + "br" + ">"}}

Please share output of above variable


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

Here you go.

graceandrade_1-1665103374269.png

There is no user object in analytics hence its failing hence attach same variable template on user update rule & share output )


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

This is the email triggered from user update rule

graceandrade_0-1665104838461.png

 

There is no user object in Email template hence your logic will not work

<% if (user == null) print "User Object is nulll" else "User object found"%>


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

@mgra,

So you want to trigger an email on user update and based on the user's custom property value, you are looking to conditionally format the content of the email being sent ?

 

 

Regards,
Avinash Chhetri

mgra
New Contributor III
New Contributor III

Correct but when I added the html image syntax inside the if else, it's doesn't trigger an email.

Without html tag also its not triggering correct because user object is not exposed 


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

When I removed the dollar sign on the user.customproperty11 and <img> tag it sends an email. What do you mean by user object not exposed? Is there anything I needed to do on my end for the html image syntax to work?

Can you share current working syntax & output screenshot


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

This one worked

<% if (user.customproperty11 == null) print "QR Code not found, please contact support" else print "test email notif" %>

graceandrade_0-1665364515024.png

 

While this one doesn't have an output as email didn't trigger, because of the img tag

<% if (user.customproperty11 == null) print "QR Code not found, please contact support" else print <img src="https://xxxxxxxxxxx=user.customproperty11"> %>

Its working for me 

Steps

1. create template with html =false

2. save

3. update email template to html= true

4. email template print message in single quote

rushikeshvartak_2-1665369091492.png

 

 

O/p

rushikeshvartak_1-1665369068480.png

 


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

Thanks a lot, Rushikesh. It's now working for the User Update Rule. I'll try to play around with the Analytics configuration to see if it will trigger an email too using the conditional statement and Analytics variable.

mgra
New Contributor III
New Contributor III

I just noticed that when I used the syntax below it sends an email but it doesn't get the expected result.

<% if (user.customproperty11 == null) print "QR Code not found, please contact support" else print '<img src="https://xxxxxxxxxxx=user.customproperty11">' %>

I even tried the different variables for the img src like ${user?.customproperty11} and ${user.customproperty11} and yet it's not displaying the QR code.

graceandrade_0-1665478631438.png

I also tried the HTML links -syntax but it's not working as expected.

<% if (user.customproperty11 == null) print "QR Code not found, please contact support" else print '<a href="${user.customproperty64}">Register for Passwordless Authentication</a>' %>

graceandrade_1-1665478885434.png

On first email if you download picture does it working


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

mgra
New Contributor III
New Contributor III

Nope, it doesn't work.