This is a specific example of how you can use Apona's Calculated Fields to Ccreate a function for specific address components, replacing the Account.Country field in the code below with the appropriate field. This was tested with a street line as well and it changed 123 MAIN ST to 123 Main St.
Calculated Field contents:
function titleCase(str) {
// Step 1. Lowercase the string
str = str.toLowerCase();
// Step 2. Split the string into an array of strings
str = str.split(' ');
// Step 3. Create the FOR loop
for (var i = 0; i < str.length; i++) {
str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1);
}
// Step 4. Return the output
return str.join(' ');
}
({!Account.Country})
If exceptions are needed to avoid directionals or PO boxes from returning incorrectly (ex/ P.o., Nw), use this code:
In the highlighted code below, you will just need to add any other exception values. Note they need to be in lowercase because the first part of the code turns everything into lowercase before applying the uppercase function to the first character.
function titleCase(str) {
// Step 1. Lowercase the string
str = str.toLowerCase();
// Step 2. Split the string into an array of strings
str = str.split(' ');
// Step 3. Create the FOR loop
for (var i = 0; i < str.length; i++)
if (["nw","ne","p.o.","fm","se","sw"].indexOf(str[i])>=0)
{str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1).toUpperCase()}
else
{str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1)};
// Step 4. Return the output
return str.join(" ");
}
({!Street})