
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 12:45 PM
I have the below script the is giving me the total time charge to a particular task per record. Can someone help me in getting the script to add all of the different totals into one combined total?For example the below screen shot, shows 127.0 and 20.0. I would like the script to print out 147 which is the total combined.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('time_card');
gr.addQuery('u_project', current.sys_id);
gr.query();
while (gr.next()) {
var total = gr.sunday + gr.monday + gr.tuesday + gr.wednesday + gr.thursday + gr.friday + gr.saturday;
gs.addInfoMessage(total);
//gr.setWorkflow(false);
//gr.update();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 12:58 PM
You need to move total outside the loop:
var total = 0;
var gr = new GlideRecord('time_card');
gr.addQuery('u_project', current.sys_id);
gr.query();
while (gr.next()) {
total = total + gr.sunday + gr.monday + gr.tuesday + gr.wednesday + gr.thursday + gr.friday + gr.saturday;
gs.addInfoMessage(total);
//gr.setWorkflow(false);
//gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 12:58 PM
You need to move total outside the loop:
var total = 0;
var gr = new GlideRecord('time_card');
gr.addQuery('u_project', current.sys_id);
gr.query();
while (gr.next()) {
total = total + gr.sunday + gr.monday + gr.tuesday + gr.wednesday + gr.thursday + gr.friday + gr.saturday;
gs.addInfoMessage(total);
//gr.setWorkflow(false);
//gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 01:12 PM
I think just small correction, you would have mistakenly typed it,
total = total + gr.sunday + gr.monday + gr.tuesday + gr.wednesday + gr.thursday + gr.friday + gr.saturday;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 01:17 PM
Thanks, edited post with correction.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 01:00 PM
Hello Edwin,
May be you can try to get the total saved in one custom field and then use the GlideAggregate SUM to calculate the sum of that custom field for all the record.