Using If-else conditional logic in Saviynt Email Templates to differentiate the content of the email
Sometimes we need to send different email content based on conditions that we cannot achieve using groovy script then in that situation we can use the below code to meet the requirements.
Here is a sample requirement and the steps to achieve the same.
Short Requirement:
When a New Account is Created Trigger an Email notification to the User's private email address if the user's employee type is external, else trigger a notification to the Manager and the user and manager email content is different as described below
Detailed requirement:
If the user's employee type is 'External' and the user has a private email address(stored in user customproperty5)
Hi ${user.firstname} ${user.lastname},
A new Personal AD account has been created for you. Your manager is ${manager.firstname} ${manager.lastname}
Account name: ${account_name}
Account DisplayName: ${account?.displayName}
Department: ${account.customproperty12}
Password: ${randompassword}
Request you reset the password after initial use.
If the user is not matching the above condition then a notification to the manager
Hi ${manager.firstname} ${manager.lastname},
A new Personal AD account has been created for your subordinate. Your subordinate is ${user.firstname} ${user.lastname}
User Start Date: ${new java.text.SimpleDateFormat("dd-MM-YYYY").format(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(user.startdate.toString()))}
Account name: ${account_name}
Account DisplayName: ${account?.displayName}
Department: ${account.customproperty12}
Password: ${randompassword}
Request you reset the password after initial use.
Here are the steps to achieve the above requirement.
Step 1: Add If-else and Convert the text to HTML
a. Using https://wordtohtml.net/ convert your plain word text into html
b. Remove the new lines and make the entire text into a single line
c. Including if-else condition the email template looks like below, you can preview the format in the https://wordtohtml.net/ Visual Editor by pasting the below code in HTML Editor,
TO:
<% if (user?.employeeType == 'External' && account?.customproperty5 !='')print"${user?.customproperty5}" else print"${manager.email}" %>
Note: Normal groovy script can also be used for generating the above TO address value, you can chose whatever works for you
Body:
<%
if (user?.employeeType == 'External' && account?.customproperty5 !='')
print"<div>Hi ${user.firstname} ${user.lastname},</div><div><br></div><div>A new Personal AD account has been created for you. Your manager is ${manager.firstname} ${manager.lastname}</div><div><br></div><div>Account name: ${account_name}</div><div>Account DisplayName: ${account?.displayName}</div><div>Department: ${account.customproperty12}</div><div>Password: ${randompassword}</div><div><br></div><div>Request you reset the password after initial use.</div>"
else print"<div>Hi ${manager.firstname} ${manager.lastname},</div><div><br></div><div>A new Personal AD account has been created for your subordinate. Your subordinate is ${user.firstname} ${user.lastname}</div><div><br></div><div>User Start Date: ${new java.text.SimpleDateFormat("dd-MM-YYYY").format(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(user.startdate.toString()))}</div><div>Account name: ${account_name}</div><div>Account DisplayName: ${account?.displayName}</div><div>Department: ${account.customproperty12}</div><div>Password: ${randompassword}</div><div><br></div><div>Request you reset the password after initial use.</div>"
%>
Step 2: Log in to Saviynt Portal and create a new email template, select Content As HTML : False
Step 2 and Step 3 are needed only when you encounter issues, if not you can directly save the email template Content as HTML, and see whatever works for you. and leave the your option in the comment section below
Step 3: Click on Edit email template, select Content As HTML : True
Step 4: Attach the email template to the Endpoint
Admin => Identity Repository => Security Systems => Select your security System and click on Endpoint => in the "Add Email Templates" click on +ADD and configure as below
Comments
Post a Comment