and more in a single search tool across platforms. Read the announcement here. |
11/08/2023 01:59 AM
Hi Team,
We want to put a check in the email template body that if this parameter ${service_accounts_list} returns any value then print the same value else print some message.
We are using the below code but it is not working.
<% if (${service_accounts_list} != null)print "${service_accounts_list}" else print "xyz"%>
It seems, the problem is when we are putting the variable ${service_accounts_list} in if condition, also tried with if (${service_accounts_list} == "") .
Could you please help on this?
The email is getting triggered through user update rule.
Thanks
Solved! Go to Solution.
11/08/2023 09:28 PM
can you share result of variable in email body
11/08/2023 09:56 PM
Thanks for the response,
when no value is fetched by the variable it is showing as below:
when there is some value, it is coming as below:
Service Account: [Name of the service account]
11/08/2023 09:42 PM
Hello @Ajit,
Could you please try below
Using if-else: <% if (null!=service_accounts_list && service_accounts_list!='') print "${service_accounts_list}" else print "xyz" %>
Using ternary operation: ${service_accounts_list.size() == 0 ? 'xyz': service_accounts_list}
Thanks.
11/09/2023 12:03 AM
Hi @sudeshjaiswal ,
The ternary operation worked. Thanks a lot.
Could you please suggest how can we remove extra bracket coming in the variable result from the email template?
Thanks
11/09/2023 12:40 AM
Hello @Ajit,
You can use the replace option,
${service_accounts_list.size() == 0 ? 'xyz': service_accounts_list.replace('[[', '').replace(']]', '')}
Thanks.
11/09/2023 01:41 AM
Hi @sudeshjaiswal ,
Tried the suggested replace option, but its not working. Any alternative way to do this?
11/09/2023 01:43 AM
Hello @Ajit
What error are you seeing the logs?
Thanks.
11/09/2023 02:01 AM
The error in logs showing while sending the email. - "ERROR","Error while sending emailText must not be null,
Thanks
11/09/2023 08:07 PM - edited 11/09/2023 08:47 PM
Hello @Ajit,
Can you please try using the below query,
${service_accounts_list.size() == 0 ? 'xyz': service_accounts_list.toString().replace("[[", "").replace("]]", "")}
or
${service_accounts_list.size() == 0 ? "xyz" : service_accounts_list.isEmpty() ? "" : service_accounts_list.toString().replace("[[", "").replace("]]", "")}
Thanks.
11/14/2023 04:35 AM
@sudeshjaiswal Thanks a lot! it worked