Display on parent doc the sum of values in a field in responses docs

Hi !

Sorry if this has been answered before, but I’m in a hurry, and 1/2 hour searching in help and forums didn’t solve my problem. Here it is :

Let’s say that I have a list of cities, as main documents. Each city has a few response docs containing ,let’s say, a house. Each house as a field named “Capacity” to store the number of people that can live in it.

Now, I want the parent document (city) to display the total capacity of the city, i.e the sum of all its houses capacities. This count should auto-referesh if a house is added or modified.

How can I do it ? In a embedded view, the response docs can’t be totaled. In a computed on display field ? but how ?

Thanks to give me some advice !

Subject: Display on parent doc the sum of values in a field in responses docs

Hello Francois,using “@getdocfield” and “@setfield” you can update a field in the parent doc from the response doc. So when a “house” respnse doc is created or changed you can update the total capacity in the city document.

Maybe it can help you

regards axel

Subject: If you only want to display the value when form open

you can do this in Formula or script quite easily

In formula

Create a view that lists ONLY the child documents

sorted so you can do the lookup

Note: you need to take OFF the view option to show responses

Make the first columm $Ref (sortable)

Make the second column the counting field i.e. Capacity

(i assume this is type number)

lets name this CapacityView

(or whatever you like)

Create a computed for display field on the parent form

Type Number

Formula for this

L := @Dblookup( “” ; “” ; “CapacityView” ; @DocumentUniqueID ; 2 ) ;

@if( @IsError(L) ; 0 ; @sum(L) )

with script you have the option of a rather different solution:

put some code in the QueryOpen of the parent

to find all teh responses

sum the Capacity form each

place in the CFD item

Subject: RE: If you only want to display the value when form open

Thanks Alan, it works like a breeze and does exactly what i want it to do.

The only thing I had to do is use @text($ref) for the first column instead of simply using $ref.

Same thing the field formula, where I used @text(@documentuniqueID).

Thanks a lot.

Subject: YAVW + Mea Culpa

I forgot UNID is ‘special text’ and need to be forced to text

well done