Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Email Templates Multiple Conditionals

alanrojas
New Contributor
New Contributor

Hello,

We are attempting to implement an email template that displays information about a user based on any null values they may have.

e.g.: if (user.costcenter == null) print "[something1...]" if (user.employeeID == null) print "[something2...]" if ...

We have attempted various methods to achieve this use case, but the email never arrives as evidenced by the error message in the logs: 'Error while sending email'.

Could someone please assist us with this issue?

Thank you in advance.

 

Regards,

Alan Rojas

23 REPLIES 23

Murmur
Regular Contributor II
Regular Contributor II

Hi Alan, 

I had a similar issue a couple of weeks ago. This is how I fixed it.

Syntax

<% if (user.customproperty10 == 'Internal' || user.customproperty10 == 'Student' ) print "Internal or Student" else if (user.customproperty10 == 'External' ) print 'External' %>

Additional Issue

It might not work right away (like many things in Saviynt).

  • Create a new template
  • Select Content as HTML: false
  • Save
  • Reopen Template
  • Select Content as HTML: true

Then it should work. 

Additional disclaimer 

Some fields, like Subject and To have a max length of 255 chars (including the code). If it is any longer it will fail with a badly described error in the logs.

I hope this helps you!

Hello!

Thank you for your response, we have tried, but is not exactly the use case we want.

We need to use several if statements instead of an "elif". You know how could we achieve this?

Thank you,

Regards,

Alan Rojas

Murmur
Regular Contributor II
Regular Contributor II

Have you tried just using several if clauses instead? I don't see any issue with doing so - There is no need for an else if.

We have tried it but it will show us the error mentioned above.

Murmur
Regular Contributor II
Regular Contributor II

Maybe try something like 

if (user.costcenter == null) print "[something1...]" else print ""

This way you can rule out, that your condition (user.costcenter == null) is the issue. If it is still not working, you should take a close look at the conditions you are using. 

Hello,

We have tried that but still no success... As you said, we have ruled out that the condition "equals null" is not the problem.

Please share what you tried so far


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

rushikeshvartak
All-Star
All-Star

Provide more context for your ask.

  1. where is email template is attached?
  2. how email template is triggered or tested ?

Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

This is the original email template, we have tried with several modifications but no success:

alanrojas_0-1711475186451.png

 

igorvt77
New Contributor II
New Contributor II

A few other things to try:
1) Try user?.<attribute name>  ex:  user?.displayname
I have seen issues with the email templates where this check will help with the parser errors.
2) Also for some variables, Saviynt has a bad habit of needing the case of the attribute name to match what is in the database table. I know it should only apply for SQL queries but its worth a shot.  For example:  systemusername is actually systemUserName
https://docs.saviyntcloud.com/bundle/SSM-DB-Schema-Reference-v55x/page/Content/Identity-Repository-S...

Can you share result of below

To get what variables are present to use in the email template, check using the below expression. By putting it in the email body, it will print all variable names with values, and then accordingly, you can use it:


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

 

Also change variables 

user?.systemUserName

user?.displayName

user?.manager


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Hi, after trying the following email templates:

Dear IT Services,<br><br>Critical attributes are missing for the user ${user.displayname}. <br>

 

<ul>
<%if(user?.employeeID == "")print "<li>EmployeeID<br></li>"%>
<%if(user?.systemusername == "")print "<li>SystemUsername<br></li>"%>
<%if(user?.costcenter == "")print "<li>Cost Center<br></li>"%>
<%if(user?.manager == "")print "<li>Manager<br></li>"%>
</ul>
Best regards,<br><br>Your friendly IAM system<br><br>

 

AND

 

<ul>
<%if(user?.employeeID == null)print "<li>EmployeeID<br></li>"%>
<%if(user?.systemusername == null)print "<li>SystemUsername<br></li>"%>
<%if(user?.costcenter == null)print "<li>Cost Center<br></li>"%>
<%if(user?.manager == null)print "<li>Manager<br></li>"%>
</ul>
Best regards,<br><br>Your friendly IAM system<br><br>

 

with a user who has an empty costcenter, we still get the following error

 

Error while sending emailText must not be null
2024-04-09T12:18:53+02:00-ecm-worker--null-84vr9--java.lang.IllegalArgumentException: Text must not be null at com.saviynt.ecm.services.EmailerService.sendMail

 

Could you please attach a working sample adapted to our email template?

Share email template screenshot 


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Here´s the screenshot:

alanrojas_0-1712676937099.png

Thank you,

 

Regards,

Alan Rojas

 

Does email gets trigger without dynamic variables ?


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Yes, it works. The problem arises whenever we attempt to add more if conditions.

Add condition one by one and validated which variable is breaking


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

alanrojas
New Contributor
New Contributor

 We have tried to validate each attribute one by one and the ones that are not working are Systemusername and EmployeeID. Any clue why these are not working properly?

Thank you.

 

Regards,

Alan Rojas

Try 

user?.systemUserName

user?.employeeId


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

We have tried with the "?" and without it, it is not working either way.

Then variable is not supported


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

alanrojas
New Contributor
New Contributor

So there is no way Saviynt will allow us to complete this use case? Is there any workaround so we can achieve our goal?

Thank you.

No. Please raise idea ticket


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.