Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Smartcase use in Transactional messages

Avatar

Level 2

Hi,

 

What's the best way to use the syntax for Smartcase (capitalization of the first letter of a name) for the personalization in Adobe Campaign Classic, when your personalization syntax is <%= rtEvent.ctx.firstName.@value %>

 

 

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi, 

 

I think the confusing thing here is the person answering previously is making the assumption that you have a custom personalisation block on your instance called "toSmartCase" which is likely not available on your installation.

 

What they have done is created a personalisation block external to the template called "toSmartCase" which contains some custom javascript function .toSmartCase().  They are then asking you to include this and it does not exist.

 

I have 2 solutions for you and you can test this in any template MKT or RT.

 

<!--  This section is just to fake up the rtEvent variable as you have documented in your support ticket -->

 

<%

var rtEvent = <rtEvent><ctx><firstName value="paul sheppard"/></ctx></rtEvent>;

%>

<!--

This section is some javascript to add a <string>.toProperCase() function to all strings in the template.

You can exteneralise this if required, but you would have to add it to a personalition block, and then include it.

I would suggestion for now just to add it to your template.

-->

<%

String.prototype.toProperCase = function() {
var words = this.split(' ');
var results = [];
for (var i = 0; i < words.length; i++) {
var letter = words[i].charAt(0).toUpperCase();
results.push(letter + words[i].slice(1));
}
return results.join(' ');
};

%>

 

<!-- This first one is a simple version to captialise the first letter of a variable and does not need the toProperCase() function, if this is enough for you, then just use this.-->

<p><%= rtEvent.ctx.firstName.@value.substring(0,1).toUpperCase()+rtEvent.ctx.firstName.@value.substring(1,100).toLowerCase() %></p>

 

<!-- This second example use the previous toProperCase function and will smart case the whole string -->

 

<p><%= rtEvent.ctx.firstName.@value.toProperCase() %></p>

View solution in original post

0 Replies

Avatar

Community Advisor

Hello @kkoor ,

 

You can use the personalization block and call the toSmartCase function in personalization block and pass the event variable to function then print the value in template.

 

Thanks,

Manoj

Avatar

Level 2

Hi Manoj, Thank you for your feedback, but when I use personalization blocks, I can't see where to retrieve the functions. Were you thinking of this: <%= .toSmartCase() + rtEvent.ctx.firstName.@value %> (note it's for transactional (in commercial campaigns I see the functions, but not in transactional)

 

Or do I need to add it in a script??

Avatar

Community Advisor
Hello @kkoor , You can define the function in Personalization block and store the value of function in variable and then this variable will be printed in the HTML.

Avatar

Level 2
is this going to work: <%= rtEvent.ctx.firstName.@value %> &lt;script&gt;<%@ include view='toSmartCase'%>; document.getElementById("firstName").innerHTML = toSmartCase(); &lt;/script&gt;

Avatar

Community Advisor
@kkoor, Try this<%@ include view='toSmartCase'%> <% var FirstName=rtEvent.ctx.firstName.@value %> <%= FirstName.toSmartCase(); %>

Avatar

Correct answer by
Employee

Hi, 

 

I think the confusing thing here is the person answering previously is making the assumption that you have a custom personalisation block on your instance called "toSmartCase" which is likely not available on your installation.

 

What they have done is created a personalisation block external to the template called "toSmartCase" which contains some custom javascript function .toSmartCase().  They are then asking you to include this and it does not exist.

 

I have 2 solutions for you and you can test this in any template MKT or RT.

 

<!--  This section is just to fake up the rtEvent variable as you have documented in your support ticket -->

 

<%

var rtEvent = <rtEvent><ctx><firstName value="paul sheppard"/></ctx></rtEvent>;

%>

<!--

This section is some javascript to add a <string>.toProperCase() function to all strings in the template.

You can exteneralise this if required, but you would have to add it to a personalition block, and then include it.

I would suggestion for now just to add it to your template.

-->

<%

String.prototype.toProperCase = function() {
var words = this.split(' ');
var results = [];
for (var i = 0; i < words.length; i++) {
var letter = words[i].charAt(0).toUpperCase();
results.push(letter + words[i].slice(1));
}
return results.join(' ');
};

%>

 

<!-- This first one is a simple version to captialise the first letter of a variable and does not need the toProperCase() function, if this is enough for you, then just use this.-->

<p><%= rtEvent.ctx.firstName.@value.substring(0,1).toUpperCase()+rtEvent.ctx.firstName.@value.substring(1,100).toLowerCase() %></p>

 

<!-- This second example use the previous toProperCase function and will smart case the whole string -->

 

<p><%= rtEvent.ctx.firstName.@value.toProperCase() %></p>

Avatar

Level 2
@psheppar, This works. Thank you. There's only one thing, when someone has a name such as Marie Ann, then ann is in lowercase. Is it possible to have each word as ProperCase? I try to change it, but it doesn't seem to pick up the changes. Any thoughts. Thank you so much.

Avatar

Employee
You will need to add the toProperCase() to your template body as shown, then use the second example to implement, this should propercase as you require

Avatar

Level 2
@psheppar, this is really strange. So it works when you look at your email in PREVIEW with personalization. Then it uses ProperCase, however, at the time of send, the personalization is still in the format as the RT data was pushed to Adobe. During a real send the personalization does not change. This is strange.

Avatar

Employee
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> </HEAD> <BODY> <P>POC Proper Case Test</P> <% String.prototype.toProperCase = function() { var words = this.split(' '); var results = []; for (var i = 0; i < words.length; i++) { var letter = words[i].charAt(0).toUpperCase(); results.push(letter + words[i].slice(1)); } return results.join(' '); }; %> <p><%= rtEvent.ctx.firstName.@value.substring(0,1).toUpperCase()+rtEvent.ctx.firstName.@value.substring(1,100).toLowerCase() %></p> <p><%= rtEvent.ctx.firstName.@value.toProperCase() %></p> </BODY></HTML>

Avatar

Employee
I have just execute the above template, With the following event body and it worked as expected: <ctx> <firstName value="Paul Sheppard"/> </ctx>

Avatar

Level 2
@psheppar, made one small change so that it also works when someone writes its name in all uppercases. Works like a charm now. Thank you so much. String.prototype.toProperCase = function() { var words = this.split(' '); var results = []; for (var i = 0; i < words.length; i++) { var letter = words[i].charAt(0).toUpperCase(); var letters = ""; if(words[i].length > 1) { letters = words[i].slice(1).toLowerCase(); } results.push(letter + letters); } return results.join(' '); };