Monday, June 28, 2010

Microsoft CRM 4.0 OnChange Jscript to Proper Case Last Name

Copy and paste the following jscript to the OnChange event of Contact Last Name field.

///Conver Last Name to ProperCase///

function toProperCase(s)
{
return s.toLowerCase().replace( /\b((m)(a?c))?(\w)/g,
function($1, $2, $3, $4, $5) { if($2){return $3.toUpperCase()+$4+$5.toUpperCase();} return $1.toUpperCase(); });
}
var oldName = crmForm.all.lastname.DataValue;
crmForm.all.lastname.DataValue = toProperCase(oldName);

Knowledge from http://stackoverflow.com/questions/196972/convert-string-to-proper-case-with-javascript