How do you set the value of a currency field?

___miked___
Mega Contributor

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.

14 REPLIES 14

Perfect, I was testing on my instance. But you have solved. Thanks!


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); .


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.


Mike - It should work . can you check if the field name is right ? I assume field name to be u_total_fields


Yes, thanks.   I double checked and that's the correct field name.