How to create calculated field script

kmathis
Kilo Contributor

I have created the following in a calculated field to add the numerical contents of three fields:

var a = parseInt(g_form.getValue('current.u_currency'));

var b = parseInt(g_form.getValue('current.u_currency_3'));

var c = parseInt(g_form.getValue('current.u_currency_5'));

var d = a+b+c;

g_form.setValue('current.u_total_project_capex',d);

It returns 0.   Any ideas?

Thank you!

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Kari,



  Here is your calculated value


if(!isNaN(current.u_currency) && !isNaN(current.u_currency_3) && !isNaN(current.u_currency_5)){


current.u_total_project_capex=(parseInt(current.u_currency)+parseInt(current.u_currency_3)+parseInt(current.u_currency_5)).toString();


}




Thanks,


Abhinay


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi Kari,



When you say "calculated field"? Are you referring to the calculated value in the dictionary entry?



find_real_file.png


Ishant Goyal1
Tera Contributor

Hi Kari,



You dont have to use Current object with g_form.getValue() function. It only takes the field name as an argument from which you want to fetch the value and use.



Correct code will be as following.



var a = parseInt(g_form.getValue('u_currency'));


var b = parseInt(g_form.getValue('u_currency_3'));


var c = parseInt(g_form.getValue('u_currency_5'));


var d = a+b+c;


g_form.setValue('u_total_project_capex',d);



Regards,


Ishant


Abhinay Erra
Giga Sage

Kari,



  Here is your calculated value


if(!isNaN(current.u_currency) && !isNaN(current.u_currency_3) && !isNaN(current.u_currency_5)){


current.u_total_project_capex=(parseInt(current.u_currency)+parseInt(current.u_currency_3)+parseInt(current.u_currency_5)).toString();


}




Thanks,


Abhinay


Abhinay,



Thank you!!!   That worked perfectly.....and I'm pretty certain I would have never figured that out.



Best Regards,



Kari