Hello there,
I have been trying to insert a user event custom script that would take the value from one field (currency field), convert it to words, and then insert the new value in another field (free form text).
I got this one from a website and it was working there, but not being a developer, not sure on how to get it to work in NetSuite.
The three fields I am trying to get the data from (currency fields) are:
custrecord9, custrecord10, custrecord11.
The fields I am trying to insert are
custrecord14, custrecord15, custrecord16.
All your help is appreciated.
See below -
// Convert numbers to words
function Num_toWords (){
// American Numbering System
var th = ['','thousand','million', 'billion','trillion'];
// uncomment this line for English Number System
// var th = ['','thousand','million', 'milliard','billion'];
//Declair Variables
var dg = ['zero','one','two','three','four', 'five','six','seven','eight','nine'];
var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen', 'seventeen','eighteen','nineteen'];
var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
//Get Variables
var record = nlapiGetNewRecord();
var contractamount = record.getFieldValue('custrecord9');
var costcap = record.getFieldValue('custrecord10');
var exceedlimit = record.getFieldValue('custrecord11');
//Set field values
record.setFieldValue('custrecord14', '');
record.setFieldValue('custrecord15', '');
record.setFieldValue('custrecord16', '');
//Calculate
if( ( type == 'create') || (type=='edit') )
var s;
{s = s.toString(); s = s.replace(/[\, ]/g,'');
if (s != parseFloat(s)) return 'not a number'; var x = s.indexOf('.');
if (x == -1) x = s.length; if (x > 15) return 'too big';
var n = s.split('');
var str = '';
var sk = 0;
for (var i=0; i < x; i++) {if ((x-i)%3==2) {if (n[i] == '1') {str += tn[Number(n[i+1])] + ' '; i++; sk=1;} else if (n[i]!=0) {str += tw[n[i]-2] + ' ';sk=1;}} else if (n[i]!=0) {str += dg[n[i]] +' ';
if ((x-i)%3==0) str += 'hundred ';sk=1;} if ((x-i)%3==1) {if (sk) str += th[(x-i-1)/3] + ' ';sk=0;}} if (x != s.length) {var y = s.length; str += 'point ';
for (var i=x+1; i<y; i++) str += dg[n[i]] +' ';} return str.replace(/\s+/g,' ');}
//Set field values
record.setFieldValue('custrecord14', s);
record.setFieldValue('custrecord15', s);
record.setFieldValue('custrecord16', s);
var id = nlapisubmitrecord (record,true);
}