Here you go. An updated version of the script that updates the parent record. Update fields as necessary. I removed the line with the getDisplayValue(), but I have a new one to set to get the record. Unfortunately my test instance was wiped this morning and I cannot fully test this code.



var parentTable = 'u_parent_table';


var childTable = 'u_child_table';


var parentField = 'u_parent'; // ref field from child to parent


var numberField = 'u_number'; // what do we want to sum up on the child


var parentTotal = 'u_total';



var sum = new GlideAggregate(childTable);


sum.groupBy(parentField);


sum.addAggregate('SUM', numberField);


sum.query();



var impacts = 0;


while (sum.next()) {


    impacts = sum.getAggregate('SUM', numberField);


    var gr = new GlideRecord(parentTable);


    gr.get(sum.u_parent); // change u_parent to the same as line 3 above


    gr.setValue(parentTotal, impacts);


    gr.update();


}