Email Template To field method error

aundreb
Regular Contributor
Regular Contributor

Hello,

I need some help with an email template. I have an email configured to go out on new account creation, however the logic for my To field seems to be evaluating as null.

Below is the to field logic:

<% if (user.username.startsWith('xt')) print "${manager?.email}" %>

I've put the manager as myself, and my account has the email field filled out. Is the startsWith method not valid for email templates? The user's username starts with xt.

No error but below is the To field population in the logs 

aundreb_0-1676391227919.png

 

9 REPLIES 9

sk
All-Star
All-Star

Do you see any error in logs?

Also does the user name of the user is starting with 'xt' with same case?


Regards,
Saathvik

aundreb
Regular Contributor
Regular Contributor

As mentioned in the original post there is no error in the log and user's name starts with xt in same case.

And I assume you configured this email template as Task completion on New Account?

try below 

 

<% if (user.username.substring(0,1).equalsIgnoreCase('xt')) print "${manager?.email}" %>

 

If still doesn't work please share the user screenshot showing username and manager field, Manager screenshot with email and also email template


Regards,
Saathvik

aundreb
Regular Contributor
Regular Contributor

This one didn't appear to work either, however it isn't showing null.

debug log:

aundreb_0-1676396424488.png

Here is the user screenshot with username and manager shown.

aundreb_1-1676396735580.png

 

Manager screenshot with email filled out

aundreb_2-1676396880320.png

 

Email template screenshot:

aundreb_3-1676396997951.png

 

 

Can you share output of below (add into email body)

 

${this.binding.variables.each {k,v -> println "$k = $v" + "<" + "br" + ">"}}

Got the below in the debug log

aundreb_1-1676469871514.png

 

aundreb_0-1676469830144.png

 

can you enable advanced css on email template


Regards,
Saathvik

aundreb
Regular Contributor
Regular Contributor

The solution that worked was

<% if(user.username.substring(0,2).equalsIgnoreCase(‘xt’)) print “${manager?.email}” %>

@sk your previous solution was good just needed to be substring(0,2) and not (0,1)

Thanks.

Just to understand Enable Advanced CSS worked along with corrected substring statement?


Regards,
Saathvik