Sunday, March 10, 2019

Ability to add comma on the free-form custom field via client script

Customer would like to add a comma on the Currency field however the system automatically remove the comma being set in the
script.

To be able to add a comma, they could use a Free-Form Text so that we could store the value with comma on it and use the script below:

function addCommanOnFreeForm()
{
var total = nlapiGetFieldValue('total');
var withComma = addCommas(total);
nlapiSetFieldValue(<customfieldfreeform_id>,withComma);
return true;
}

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

No comments:

Post a Comment