Need to SUM the contents of several fields

amacqueen
Mega Guru

I don't know if this is possible but lets say I have 5 fields on a form each of which are called field 1 to 5 respectively and I want to add them and put the sum in field 6.

I've seen the WIKI Article GlideAggregate - ServiceNow Wiki but don't know if that will work for me as I'm a javascript idiot.

Does anyone have any suggestions as to how best I can approach this please?

TIA

1 ACCEPTED SOLUTION

Copy paste this code and check




var a = parseInt(current.u_initiation_days_);


var b = parseInt(current.u_development_days_);


var c = parseInt(current.u_configuration_days_);


var d = parseInt(current.u_testing_uat_days_);


var e = parseInt(current.u_pm_days_);


var f = parseInt(current.u_external_days);




var g = parseInt(a)+parseInt(b)+parseInt(c)+parseInt(d)+parseInt(e)+parseInt(f);




gs.log('Total :'+g);



current.u_total_days = g;


View solution in original post

19 REPLIES 19

Harish I created the following business rule after making Alex's script inactive and it fails for me, any ideas?



Before insert, update and delete



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


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


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


  var d = parseInt(g_form.getValue('u_testing_uat_days_'));


  var e = parseInt(g_form.getValue('u_pm_days_'));


  var f = parseInt(g_form.getValue('u_external_days'));


  var g = a+b+c+d+e+f;


  g_form.setValue('u_total_days',g);


g_form is client side object   Current is server object   Use current in business rule it can work     Regards, Harish.

RFW Days.PNGThanks Harish and Brad I have changed the BR but it still doesn't work, I've checked the field names and they are correct. I have attached a screen print of my BR - does it look OK?


Copy paste this code and check




var a = parseInt(current.u_initiation_days_);


var b = parseInt(current.u_development_days_);


var c = parseInt(current.u_configuration_days_);


var d = parseInt(current.u_testing_uat_days_);


var e = parseInt(current.u_pm_days_);


var f = parseInt(current.u_external_days);




var g = parseInt(a)+parseInt(b)+parseInt(c)+parseInt(d)+parseInt(e)+parseInt(f);




gs.log('Total :'+g);



current.u_total_days = g;


Thanks Harish that worked fine, looks like I just needed to replace the var g line with yours.



Thank you all for your help