Need Business rule to convert the default value to Proper or Camel Case

sharandeep mada
Mega Contributor

Need a business rule to convert all upper case letters to Proper Case or CamelCase on a field. Right now we are having default value all in Upper case, need to change that (to Proper Case) for reporting and consistency with old data on tables. Any one already written or can help me in writing this business rule. Thanks in Advance

1 ACCEPTED SOLUTION

antin_s
ServiceNow Employee
ServiceNow Employee

Create a business rule on both insert & update, and use the method mentioned in the below URL to convert camelCase the value and update it in the GlideRecord.



javascript - Converting any string into camel case - Stack Overflow



Hope this helps. Mark the answer as correct/helpful based on impact.



Thanks


Antin


View solution in original post

3 REPLIES 3

antin_s
ServiceNow Employee
ServiceNow Employee

Create a business rule on both insert & update, and use the method mentioned in the below URL to convert camelCase the value and update it in the GlideRecord.



javascript - Converting any string into camel case - Stack Overflow



Hope this helps. Mark the answer as correct/helpful based on impact.



Thanks


Antin


Community Alums
Not applicable

Hello Sandeep,

 

Could you please send me your code for all Upper case letters when user type anything on field

Jason Siegrist
Giga Guru

Doing a little coding ...   This will cover PROPER Casing of Names 

function capitializeLetter(str, charNumber){
  return str.slice(0,charNumber) + str.charAt(charNumber).toUpperCase() + str.slice(charNumber +1);
}

function propereCase(str)
{
  var firstPass = str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
  var finalStr = firstPass;
  var specialStartCases =["Mc","O'","Mac"];
      
      specialStartCases.forEach(function(specialCase){
        if (finalStr.indexOf(specialCase)===0){
          //to Upper the letter AFTER the specialCase
          finalStr = capitializeLetter(finalStr, specialCase.length);
        }                          
      });
        
  var hyphenLocation = finalStr.indexOf('-');
      if (hyphenLocation > -1){
         finalStr = capitializeLetter(finalStr, hyphenLocation + 1);
      }
return finalStr;
}


var myText = "williams-brown";
	
var myTextInTitleCase = propereCase(myText);