Smartcase use in Transactional messages

Avatar

Avatar

kkoor

Avatar

kkoor

kkoor

25-10-2020

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 %>

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

psheppar

Employee

Avatar

psheppar

Employee

psheppar
Employee

18-11-2020

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>

kkoor
@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.
psheppar
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
kkoor
@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.
psheppar
<!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>
psheppar
I have just execute the above template, With the following event body and it worked as expected: <ctx> <firstName value="Paul Sheppard"/> </ctx>
kkoor
@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(' '); };

Answers (1)

Answers (1)

Avatar

Avatar

_Manoj_Kumar

MVP

Avatar

_Manoj_Kumar

MVP

_Manoj_Kumar
MVP

26-10-2020

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