Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to sum field total value from list of records and copy that result sum into another table field

Kishore8
Kilo Guru

Here my script:

but not working it..

Business rule: table :incident

var totalA = 0;

  totalA += current.u_used_amount;

var bRec = new GlideRecord('u-details');

bRec.query();

if(bRec.next()){

bRec.u_reaming_balance = totalA;

bRec.update();

}

find_real_file.png

8000+5000+3000=16000 , display result sum in u_details table

Table: u_details

Field: u_remaing_balance

1 ACCEPTED SOLUTION

Hi Srivastav,




(function executeRule(current, previous /*null when async*/) {


var cal = 0;


var gr = new GlideRecord('incident');


gr.addQuery('category', 'software');     // is it mandatory ??


gr.query();


while(gr.next())


cal = parseInt(cal) + parseInt(gr.u_used_amount);



var bRec = new GlideRecord('u_details');


bRec.addQuery('fieldname', 'pass the filter value here'); //if   it is new table of field then the field is empty , WHAT   DO NOW    


bRec.query();,


if(bRec.next()){


bRec.u_reaming_balance = cal;


bRec.update();


}


})(current, previous);


View solution in original post

15 REPLIES 15

Dave Smith1
ServiceNow Employee
ServiceNow Employee

If you want that value displayed on the list, use Configure > List Calculations to add a sum value to the bottom of that column.



It won't provide a running total of all values, but just those being displayed.



As a matter of interest, what will this value be used for?   If you're doing reports, PA contains functionality to see historical data.