Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to convert inputted arithmetic numbers to Chinese numerals

sugit
Tera Contributor

The user enters a specific address in the address field. Then, when the Save button is pressed, the user wants to convert the arithmetic numbers to Chinese numerals and save them ( 5-chome to  五-chome).
Is there a better way to do this?
Thanks, everyone.

1 ACCEPTED SOLUTION

Eshwar Reddy
Kilo Sage

Hi @sugit 
Create On Before BR  and use the below script 

 

function arabicToChinese(num) {
const chineseNumbers = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
return num.toString().split('').map(digit => chineseNumbers[parseInt(digit)]).join('');
}

// Assuming 'address' is the field you're working with

address --> replace address with your field name
if (current.address) {
current.address = current.address.replace(/\d+/g, function(match) {
return arabicToChinese(match);
});
}

 

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution.

Thanks
Eshwar



View solution in original post

3 REPLIES 3

Eshwar Reddy
Kilo Sage

Hi @sugit 
Create On Before BR  and use the below script 

 

function arabicToChinese(num) {
const chineseNumbers = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
return num.toString().split('').map(digit => chineseNumbers[parseInt(digit)]).join('');
}

// Assuming 'address' is the field you're working with

address --> replace address with your field name
if (current.address) {
current.address = current.address.replace(/\d+/g, function(match) {
return arabicToChinese(match);
});
}

 

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution.

Thanks
Eshwar



@Eshwar Reddy 

Really, thank you.

you have helped me solve my issues.

Hi @sugit 


Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution.

Thanks
Eshwar