Get Sum from Child list

Feb 29, 2012 at 7:47 AM


i have 2 list, let say "Issue" list is as Parent and "Item" list as Child, i have successfully created custom display form for "Issue" list and passing parameter to Item list when add new item.

How to get sum from child list (column "hours") and update into parent list (column "Sum Hours") in the NewItem form when click "Save button"

Parent List

Issue Sum Hours
Issue A  ?50
Issue B  
Issue C  
Issue D  

Child List

Issue Item Hours
Issue A Item 1 20
Issue A Item 2 20
Issue A Item 3 10

Thanks for help.


Feb 29, 2012 at 3:31 PM
Edited Feb 29, 2012 at 3:31 PM

To do this, you'll have to do two things.  

  1. Determine the number of hours currently for the Parent
  2. Update the number of hours

So to get 1. accomplished, you'll want to use GetListItems operation and find the parent item that is associated to the child record.  After you have done that, then you'll need to take the number of hours from the new Child item and add them to the parent item.  The operation for that would be UpdateListItems.  That's all you are going to need to do.

You could use a SPD workflow for this as well.  That may be a better option depending on the amount of traffic into these lists.

Feb 29, 2012 at 8:33 PM

Note that it is a very tricky scenario. All is good when you just add a new item, but it becomes much more complicated if you need to update or delete existing items.

Feb 29, 2012 at 10:26 PM

I agree with Christophe, unless you don't care about the total being correct over time. I usually use a DVWP to do the math real-time on page render instead so that I know it's always correct.


Feb 29, 2012 at 11:44 PM

[iOnline247] I've tried use workflow many times, no luck....

[Christope / Marc] Yes, this is very tricky scenario.... could you give me the sample of script for above scenario? if this success then no matter for update/delete item


Mar 1, 2012 at 4:22 PM

A DVWP is a Web Part you can work with in SharePoint Designer, not script. It runs server-side and is XSL-driven.