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 02:43 PM
Perfect, I was testing on my instance. But you have solved. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 01:09 PM
This should work, just noticed in SetValue() S is in CAPS.
var f1 = g_form.getDecimalValue('u_currency1');
var f2 = g_form.getDecimalValue('u_currency2');
var tot = parseInt(f1) + parseInt(f2);
g_form.setValue('u_currency3', tot); .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:11 PM
Yes, thanks, I caught that but still having issues. Everything works but for some reason I can't write the Sum to the currency field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 12:58 PM
Mike - It should work . can you check if the field name is right ? I assume field name to be u_total_fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:12 PM
Yes, thanks. I double checked and that's the correct field name.