How to add integer fields?

thisismichaelb
Tera Contributor

This seems like it should be simple...

 

I have an onChange client script running when one one of my fields changes, and for some reason, the integer field will only accept numbers up to 999.   It rounds 1,000 down to 1.   Not sure if my code is wrong, or there is something I am not aware of.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue == '') {
           return;
     }


     //adds all estimates together and puts them into the est. total field
   var req = parseInt(g_form.getValue('u_act__requirements'),10);
   var des = parseInt(g_form.getValue('u_act__design'),10);
   var dev = parseInt(g_form.getValue('u_act__dev_config'),10);
   var itt = parseInt(g_form.getValue('u_act_it_test'),10);

   var newtotal = req + des + dev + itt;


   g_form.setValue('u_act__total', newtotal);
     
}
}}

 

If I enter 1-999 in the u_act_xxx fields, it works with no issues.   As soon as you enter 1000 or anything over 1000, it mucks things up.

 

Any suggestions?

1 ACCEPTED SOLUTION

geoffcox
Giga Guru

The parseInt command stops processing at the comma. On the server side, you can use .getXMLValue() to get the number without a comma. But on the client side, one solution is to add the attribute "format=none" on the dictionary entry for that field. This will stop the comma from being displayed, and thus read by the client script.


View solution in original post

8 REPLIES 8

geoffcox
Giga Guru

The parseInt command stops processing at the comma. On the server side, you can use .getXMLValue() to get the number without a comma. But on the client side, one solution is to add the attribute "format=none" on the dictionary entry for that field. This will stop the comma from being displayed, and thus read by the client script.


Thanks Geoff!


Geoff I'm a little new to this but this is the closest i've come to finding what i need.   I simply need to total two fields but it doesmn't appear to work, can you help me out?


Here's what I have




function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


    if (isLoading || newValue == '') {  


          return;  


    }  


 


  var req = parseInt(g_form.getXMLValue('total_share_price_a'));  


  var des = parseInt(g_form.getXMLValue('deposit_payable_b'));


 


  var newtotal = req + des;


 


  g_form.setValue('loan_required_c', newtotal);  


       


}


Dave,



getXMLValue() is a server side function.



I did this in a before insert/update business rule:



current.u_integer_3 = parseInt(current.u_integer_1.getXMLValue()) + parseInt(current.u_integer_2.getXMLValue());


and it works as expected.



If you want to do this client side, you can manually remove the commas as follows (I tested this on my dev instance):



  var a = g_form.getValue('u_integer_1').replace(/,/g,"");


  var b = g_form.getValue('u_integer_2').replace(/,/g,"");


  var c = parseInt(a) + parseInt(b);


  g_form.setValue('u_integer_3',c);



Cheers,


                Geoff.