- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2014 07:24 AM
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
Solved! Go to Solution.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2014 01:57 AM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2014 07:50 AM
You can do it using parseInt() function.
For ex.
We have 5 integer fields from field1 to field5.We can add the first four field values and show the calculated value in field5 using below code.
var a = parseInt(g_form.getValue('field1'));
var b = parseInt(g_form.getValue('field2'));
var c = parseInt(g_form.getValue('field3'));
var d = parseInt(g_form.getValue('field4'));
var e = a+b+c+d;
g_form.setValue('field5',e);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2014 07:53 AM
Thanks Alex, where would I enter that code, in a client script, and would it work with both integer and decimal fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2014 07:55 AM
just create a onchange client script for field4 and copy the code and paste it in script field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2014 07:57 AM
Write befor insert Business rule and populate data.
var a = current.field1;
var b = current.field2;
var c = current.field3;
var d = current.field4;
var e = current.field5;
var f = parseInt(a)+parseInt(b)+parseInt(c)+parseInt(d)+parseInt(e)+parseInt(f);
current.fieldname = f;
Regards,
Harish.