- 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-18-2014 02:11 AM
And you have written g_form.setValue('u_total_days', g);
this line also need to replace .
G-form is client side object it doesnt work in server side.
Regards,
Harish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 02:29 PM
Harish,
Thanks for you answer above. I found it but cannot seem to get it to work. Could you help me?
This is what I have:
var gpScore = current.gpra_score; | |
var gpSup = current.gpra_supplemental; | |
var gpAdj = parseInt(gpScore) + parseInt(gpSup); | |
gpAdj = current.gpra_adjusted_score; |
the two fields being added are both choice fields and the field I'm dropping the variable into is a string. Not sure if that matters, but I've tried a few variations and it doesn't seem to be working for me.
Thanks,
w
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 08:05 AM
I figured it out. The Choice field was using decimals but parseInt() only treated them as strings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2016 08:08 AM
this is the correct answer. thanks hmurikinati

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2014 08:58 AM
A business rule would definitely be the way to go here, but there's a difference in getting the value of a field between server and client side scripting. Basically both of the following will return the same value respective to where they're running:
Client (Client Scripts/UI Policies)--> g_form.getValue('fieldname');
Server (Business Rules/Script Includes) --> current.fieldname