Reg: replace method for non english letters to english

Community Alums
Not applicable

Hi Team,

I am trying to replace 
the special characters should be replaced with their equivalent:

ä ---> a
ë ---> e
ï ---> i
ö ---> o
ü ---> u
ÿ ---> y

I am trying like below in business rule 

 case "u_planned_productive":
                case "u_planned_outofservice":
                case "u_termination_pending": {
                    var keyCapry = capry_util.serviceNowToCapryFieldTransform(key);
                    var nonEngV = value.replace(/[^\x20-\x7E]+/g, "");
                   
                    jsonObj[keyCapry] = nonEngV;
                    break;
                }
         Note : .replace(/[^\x20-\x7E]+/g, "");   this one escaping the nonenglish letter for example if i will give input like Mühlhäuser   -> output i am getting Mhlhuser like this 
Actually i need output like Muhlhauser
 
Please help me if anyone know the solution 
Thanks & Regards
Bandi
1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Community Alums Please refer to this thread https://www.servicenow.com/community/now-platform-articles/remove-accents-and-special-characters-from-a-name-for-the/ta-p/2321586 . The solution suggested here works perfectly fine with accent characters.

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Community Alums Please refer to this thread https://www.servicenow.com/community/now-platform-articles/remove-accents-and-special-characters-from-a-name-for-the/ta-p/2321586 . The solution suggested here works perfectly fine with accent characters.

Community Alums
Not applicable

Hi 

I have solved above  problem like below code 

switch (field) {
                case "name":
                case "managed_by":
                 {
                    var keyCapry = capry_util.serviceNowToCapryFieldTransform(key);
                    var nonEngV = value.toString(); // Just in case, you know what I mean
                    var nonEngV1 = nonEngV.normalize('NFD'); // Canonical Decomposition
                    var ss = nonEngV1.replace(/[\u0300-\u036f]/g, ""); // Remove diacritics
                    jsonObj[keyCapry] = ss;
                    break;
                }
working as expected but if we we can update them as it follows?

ä ---> ae
ë ---> e
ï ---> i
ö ---> oe
ü ---> ue
ÿ ---> y
ß --> ss

 please help me how to translation of the umlauts like above.

 

Thanks & Regards,

bandi