05/24/2023 09:15 AM
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
05/25/2023 02:48 AM
Hello @Mohit_Sanka
Can you please confirm which email template it is for Task Complete Email or the Approval email?
Thanks,
05/25/2023 02:51 AM
05/25/2023 05:41 AM
Are you getting expected output when you print variable ?
05/25/2023 06:17 AM
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.
05/25/2023 06:21 AM
Please share that syantax
05/25/2023 07:57 AM
(${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 ""%>
05/25/2023 11:27 PM
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,