The CreatorCon Call for Content is officially open! Get started here.

Convert String (Full UTF-8) display value to currency Format?

Community Alums
Not applicable

Hi Community,

 

I have a requirement to convert String (Full UTF-8) field values to currency value .

eg : Commission Amount = 10000000

                            Expected: 10,000,000

Thanks in advance

7 REPLIES 7

Mohit Kaushik
Mega Sage
Mega Sage

Yes in that case also you can do use this. Try putting it on change of your commission amount and use the same script.

If it does not work, please share your script once.

 

Thanks,

Mohit Kaushik

 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Community Alums
Not applicable

Hi Mohit,

 

code is executing till end but value is not getting set. Kindly look at the code

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
alert('code start here');
var usd = g_form.getValue('u_usd');
var curr = usd.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

alert('usd' + 'calculating');
function addCommas(usd){
usd+= '';
var x = usd.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
alert('calculation done');
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
var curr =addCommas(usd);
alert('value set');

}

Mohit Kaushik
Mega Sage
Mega Sage

Hi Rafmine,

In which field you want to set the value, suppose it is 'abc' . Then just use this much part of code to achieve this:

//alert('code start here');
var usd = g_form.getValue('u_usd'); //here 'u_usd' is your original value field.
var curr = usd.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); // value calculation 

g_form.setValue('abc',curr); //this will set the comma separated value into 'abc' field.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)