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

If else condition in email template body not working with dynamic variable

Ajit
New Contributor III
New Contributor III

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

10 REPLIES 10

rushikeshvartak
All-Star
All-Star

can you share result of variable in email body


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

Ajit
New Contributor III
New Contributor III

Thanks for the response,

when no value is fetched by the variable it is showing as below:

Ajit_0-1699509021213.png

when there is some value, it is coming as below:

Service Account: [Name of the service account]

 

 

sudeshjaiswal
Saviynt Employee
Saviynt Employee

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.

Ajit
New Contributor III
New Contributor III

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?

Ajit_0-1699516881233.png

Thanks

 

sudeshjaiswal
Saviynt Employee
Saviynt Employee

Hello  @Ajit,

You can use the replace option,

${service_accounts_list.size() == 0 ? 'xyz': service_accounts_list.replace('[[', '').replace(']]', '')}

Thanks.

Ajit
New Contributor III
New Contributor III

Hi @sudeshjaiswal ,

Tried the suggested replace option, but its not working. Any alternative way to do this?

sudeshjaiswal
Saviynt Employee
Saviynt Employee

Hello @Ajit 

What error are you seeing the logs?

Thanks.

Ajit
New Contributor III
New Contributor III

Hi @sudeshjaiswal 

The error in logs showing while sending the email. -  "ERROR","Error while sending emailText must not be null,

Thanks

sudeshjaiswal
Saviynt Employee
Saviynt Employee

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.

Ajit
New Contributor III
New Contributor III

@sudeshjaiswal  Thanks a lot! it worked