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:19 PM
okay, I have tried below with onChange() on curreny2 field and it seems working. Can you please give a try in similar way, let' see if this helps.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var f1 = g_form.getDecimalValue('u_currency1');
var f2 = g_form.getDecimalValue('u_currency2');
var tot = parseInt(f1) + parseInt(f2);
alert(tot);
g_form.setValue('u_currency3', tot);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:25 PM
Thanks for all your effort on this. I used your code and the alert displayed the proper amount but generated the same error with it got to the setValue line.
The error is: onChange script error: TypeError: value.indexOf is not a function function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:30 PM
Here is something interesting: I changed the last line to as follows and although it still didn't assign a value to the field, it didn't throw an error either.
g_form.setValue('total_fields', "USD:"+tot+";");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:34 PM
The last line should be:
g_form.setValue('total_fields', "USD;"+tot);
No error, but no value in field either. Very strange.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 02:40 PM
Eureka! We solved it. Here's the code that worked.
var tot= 0;
var f1 = g_form.getDecimalValue('field1'); // field1 is first currency field.
var f2 = g_form.getDecimalValue('field2'); // field 2 is second currency field
tot = f1 + f2;
g_form.setValue('total_fields', "USD;"+tot); // <===This is the total.