need to update parent cost value with sum of updated child amount

Theja Yamjala
Tera Expert

Hi,

 

I have a requirement that all child records data amount roll up to parent data currency field.

I have a project that has currency field PY, CY, BY. I have 3 project tasks under that project has same 3 fields.

Once I entered some amount in those 3 project tasks, that total amount needs to roll up to project level. 

ex: PY 1 =$1, PY 2=$2, PY 3=$4. These all three project tasks amount needs to roll up to project PY and should show up as PY =$7.

Please someone help me.

Thanks,

3 REPLIES 3

bammar
Kilo Sage
Kilo Sage

You should use the examples that service now has already since Projects have alot of rollup currency fields, however an approach to take if these are custom fields are the following- In project task table create a business rule that is triggered when the field value changes,  when this happens the system totals all the values in all child project task records then takes the total and writes to the parent.  You also have to account for deletions of project task records as well as new records being added in. Also depending on how many records and even if there are multiple sublayers you may find a lag when this business rule is triggered.

sb0276
Mega Contributor

Use Business Rules on the Child record that run whenever a child record is inserted, updated or deleted.  Get the parent record and then query for all of the child records of that parent. 

Use GlideAggregate to get the Sum of each of those fields and then update the parent record with those sums.  

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/c_GlideAggr...

 

If you can't get GlideAggregate to work, Loop through and sum up each currency fields.  After looping through all child records, update the parent record with the sums.  

Hi Sb,

 

thanks for the reply . can you please provide some script.

parent field name in child record(table) is u_cost_pool, and child field name(u_py_sub_pool) that value need to roll up to parent field(py).