How do you set the value of a currency field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 10:31 AM
Been messing around with this for over an hour. Simply trying to add to dollar amounts together and display the total in a third currency field. Really can't be that hard, so what am I doing wrong?
Here's my code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var tot = 0;
var f1 = parseInt(g_form.getDecimalValue('field1')); // field1 is first currency field.
var f2 = parseInt(g_form.getDecimalValue('field2')); // field 2 is second currency field
tot = f1 + f2;
g_form.addInfoMessage(tot); // checking the value here and getting the correct sum of the above two fields.
g_form.SetValue('total_fields', tot); // <===This throws the error below.
}
Here's my (latest) error message:
var currencyCode = current.base_rate.getCurrencyCode();
I tried setting f1 without 'parseInt,' and tried using getValue rather than getDecimalValue, but neither worked.
I have a feeling the problem is right in front of me but I'm just not seeing it.
Any help would be much appreciated.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 11:49 AM
Have you defined your instances default currency?
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 12:33 PM
Where do you do that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 12:58 PM
Can give a try like below,
var f1 = g_form.getValue('field1'); // field1 is first currency field.
var f2 = g_form.getValue('field2'); // field 2 is second currency field
var tot = parseFloat(f1) + parseFloat(f2);
g_form.addInfoMessage(tot); // checking the value here and getting the correct sum of the above two fields
g_form.SetValue('total_fields', tot); // <===This throws the error below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:10 PM
Thanks for the reply and suggestion but here's what I found:
o Using getValue returns the currency code and amount (USD;30).
o parseFloat returns null.
o setValue throws onChange script error: TypeError: g_form.SetValue is not a function function () { [native code] }
Whereas the original code returns the numeric values and did the addition correctly -- but still threw an error when I tried to write that sum to the field_totals field.
var tot=0;
var f1 = g_form.getDecimalValue('field1'); // field1 is first currency field.
g_form.addInfoMessage(f1); // checking the value here and getting the correct sum of the above two fields
var f2 = g_form.getDecimalValue('field2'); // field 2 is second currency field
g_form.addInfoMessage(f2);
tot = f1 + f2;
g_form.addInfoMessage(tot);
g_form.setValue('total_fields', tot); // <===This throws the error: onChange script error: TypeError: value.indexOf is not a function function () { [native code] }
So, it looks like the problem is in writing to the total_fields currency field. Any thoughts? Thanks again for your input.