Customizing dynamic variables on Subject Line | Community
Skip to main content
Level 2
May 7, 2018
Solved

Customizing dynamic variables on Subject Line

  • May 7, 2018
  • 3 replies
  • 3093 views

Greetings community,

I am working with an email campaign, where the First Name variable is pulled from a data extension. Now, that is not the problem.

The issue at hand is that, some of these names are all capitalized, and others can be all lower case.

I have tried doing something like <% targetData.FirstName.toUpperCase(); %> but all that does is to return an empty string.

Does anyone know a work around it?

Many thanks in advance

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by andreab24032044

Hello marcel.gent.86,

Unfortunately I was unable to get both suggestions to work on my end.

However, after some more research, i found the following to work great on my end:

<%

var name = targetData.FIRST_NAME;

name = name. toLowerCase().replace(/\b[a-z]/g, function(e) {
  
return e.toUpperCase();
});

%>

<%=name%>, Best email ever!

Before

After

3 replies

Marcel_Szimonisz
Community Advisor
Community Advisor
May 8, 2018

Hello andreab24032044​,

you need to print it by <%=

<%= recipient.firstName.toUpperCase()%>

<%= and also do not use ; when printing variable

<%= recipient.firstName.toUpperCase();%>

Will throw an error.

Do you need to capitalize just the first letter? If yes then you can use something similar:

<%= (recipient.firstName.length>3) ?  recipient.firstName.charAt(0).toUpperCase() + recipient.firstName.slice(1) : "" %>

Marcel

andreab24032044AuthorAccepted solution
Level 2
May 8, 2018

Hello marcel.gent.86,

Unfortunately I was unable to get both suggestions to work on my end.

However, after some more research, i found the following to work great on my end:

<%

var name = targetData.FIRST_NAME;

name = name. toLowerCase().replace(/\b[a-z]/g, function(e) {
  
return e.toUpperCase();
});

%>

<%=name%>, Best email ever!

Before

After

Marcel_Szimonisz
Community Advisor
Community Advisor
May 8, 2018

I do not understand. It is almost the  same thing but done differently

Marcel