How to populate a cost field with the sum of two other cost fields in client script

johannaS
Tera Expert

I need to populate the 'contribution margin' field by adding the 'bill rate' and 'cost rate' fields (screenshot below).  See in the info message that these values have letters and numbers. I tried this: var billRate = g_form.getValue('u_bill_rate');
var billRateArr = billRate.split(','); but larger numbers with commas were and the decimals were giving me issues.  I'm not sure how to parse the numbers and add them before testing deadline tomorrow.  Please advise!

find_real_file.png

1 ACCEPTED SOLUTION

Jan Cernocky
Tera Guru

Hi johanna,

I believe it may be connected to current computer regional settings.

 

There are couple of options, one is to use the attribute on this dictionary entry format:none as per documentationnone: Disables automatic number formatting (for example, changes 2,500–2500).

Since this is currency field you would still need to tweak it a little bit.

The other solution may look a bit dirty but works nicely.

See the example below, I read values from two fields and showing them in the info message to prove what is actually stored in it.

The currency field starts with currency letters and then semicolon followed by the number. And it is all string.

So you need to:

1. separate the number, so split the string by semicolon to two parts

2. take just the second part (index [1])

3. replace all commas with nothing (use replaceAll instead of replace)

4. finally convert this to Float to be able to work with numbers

Feel free to mark my answer as correct/helpful if it fixes your issue.

 

find_real_file.png

find_real_file.png

View solution in original post

1 REPLY 1

Jan Cernocky
Tera Guru

Hi johanna,

I believe it may be connected to current computer regional settings.

 

There are couple of options, one is to use the attribute on this dictionary entry format:none as per documentationnone: Disables automatic number formatting (for example, changes 2,500–2500).

Since this is currency field you would still need to tweak it a little bit.

The other solution may look a bit dirty but works nicely.

See the example below, I read values from two fields and showing them in the info message to prove what is actually stored in it.

The currency field starts with currency letters and then semicolon followed by the number. And it is all string.

So you need to:

1. separate the number, so split the string by semicolon to two parts

2. take just the second part (index [1])

3. replace all commas with nothing (use replaceAll instead of replace)

4. finally convert this to Float to be able to work with numbers

Feel free to mark my answer as correct/helpful if it fixes your issue.

 

find_real_file.png

find_real_file.png