Email templates - if else condition for Dynamic Attributes

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.


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




Saviynt Employee
Saviynt Employee

Hello @Mohit_Sanka

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



Hi @sudeshjaiswal ,

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


Are you getting expected output when you print variable ?

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.



Please share that syantax

(${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 ""%>

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" : "") %>