We are delighted to share our new EIC Delivery Methodology for efficiently managing Saviynt Implementations and delivering quick time to value. CLICK HERE.

Email templates - if else condition for Dynamic Attributes

Mohit_Sanka
New Contributor II
New Contributor II

Hi Team,

We are trying to print some String value based on the Yes/No values selected in the Dynamic Attribute. We tried to use below sample but it didn't worked and throwed an groovy error.

Sample: 

User Selected :- <% if (${accessItems.collect{it.request_access_attrss.find{it.attributeName.toString().equalsIgnoreCase('Testing')}.collect{it.attributeValue}}.get(0).toString().replaceAll('\\[','').replaceAll('\\]','').replaceAll('\\,','')} == 'Yes') print "NorthAmerica" else print ""%>

Can anyone please help us how can we use the if else condition for a Dynamic attribute in the Email Template body.

Thanks & Regards,

Mohit Srinath Sanka

 

 

7 REPLIES 7

sudeshjaiswal
Saviynt Employee
Saviynt Employee

Hello @Mohit_Sanka

Can you please confirm which email template it is for Task Complete Email or the Approval email?

Thanks,

 

Hi @sudeshjaiswal ,

We are using the Email template for Request Approval and Submission.

Thanks.

Are you getting expected output when you print variable ?


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

Hi @rushikeshvartak

Yes, when we print the DA normally without the if else condition then we are getting the expected value on the Email. But when we are using the IF else condition then its throwing the groovy error.

Thanks,

Mohit.

Please share that syantax


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

(${accessItems.collect{it.request_access_attrss.find{it.attributeName.toString().equalsIgnoreCase('Testing')}.collect{it.attributeValue}}.get(0).toString().replaceAll('\\[','').replaceAll('\\]','').replaceAll('\\,','')} == 'Yes') print "NorthAmerica" else print ""%>

sudeshjaiswal
Saviynt Employee
Saviynt Employee

Hello @Mohit_Sanka ,

You may try below sample query,


Sample 1:
User Selected: <% if (accessItems.collect{it.request_access_attrss.find{it.attributeName.toString().equalsIgnoreCase('Testing')}.collect{it.attributeValue}}.get(0).toString().replaceAll('\\[','').replaceAll('\\]','').replaceAll('\\,','') == 'Yes') print "NorthAmerica" else print "" %>


Sample 2:
User Selected: <% if (accessItems.collect{ it.request_access_attrss.find { it.attributeName.toString().equalsIgnoreCase('Testing') }.collect { it.attributeValue } }.get(0).toString().replaceAll('\\[','').replaceAll('\\]','').replaceAll('\\,','') == 'Yes') { "NorthAmerica" } else { "" } %>


And also if the above query doesn't work for you may try to use a ternary operation instead of the If-else condition. It is a shorthand way of writing an `if-else` statement. It has the following syntax: `condition ? value_if_true : value_if_false`.

Sample 3:
User Selected :- <% print (${accessItems.collect{it.request_access_attrss.find{it.attributeName.toString().equalsIgnoreCase('Testing')}.collect{it.attributeValue}}.get(0).toString().replaceAll('\\[','').replaceAll('\\]','').replaceAll('\\,','')} == 'Yes' ? "NorthAmerica" : "") %>

Thanks,