Page 1 of 1

Send Total of Child List to Parent List

Posted: 27 Feb 2017
by jennifer_little
Hello,

I have a parent list called Projects for example. I have a child list called tasks which is linked to the parent list with a unique project ID. I want to calculate the total of all related child tasks and input the project total into the parent list. Example shown below:


Parent List - Projects

Project ID Project Name Project Total

000-001 Project a £15.00


Child List - Tasks

Related Project ID Task name Task total

000-001 Task 1 £10.00

000-001 Task 2 £5.00


Thanks


Jennifer

Re: Send Total of Child List to Parent List

Posted: 28 Feb 2017
by Dmitry Kozlov
Hi,

You can calculate the total either in a workflow or with JavaScript directly in a 'Project' form containing a Related Items control with the related tasks. Please, find a sample in the thread:

viewtopic.php?f=1&t=592

If you need an assistance of our support team, send a request to support@spform.com

Re: Send Total of Child List to Parent List

Posted: 14 Mar 2017
by Cloud.Ed
I am using the following code and Forms Designer 3.0.1.1. The code does not seem to set the var rows, any help?

var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
alert('Loop');
//total += parseFloat(item.Amendment_x0020_Amount)
});
alert(total)

Re: Send Total of Child List to Parent List

Posted: 15 Mar 2017
by Dmitry Kozlov
Hi,

Most likely, Forms Designer 3.0.1.1 does not support fd.relatedItems method. Please, expand the browser console (F12) and check the errors.

Re: Send Total of Child List to Parent List

Posted: 16 Mar 2017
by Cloud.Ed
Here is the error returned:

Unable to get property 'Row' of undefined or null reference.

The version of the Forms Designer App is 3.0.1.1, I'm using the Forms Designer Client 3.1.4 on the Edit form.

Thanks again!

Re: Send Total of Child List to Parent List

Posted: 16 Mar 2017
by Dmitry Kozlov
Hi,
Could you provide a screenshot of your form with the Related Items control?

Re: Send Total of Child List to Parent List

Posted: 16 Mar 2017
by Cloud.Ed
We have a total of 5 related items and this is the last, var rows = fd.relatedItems(4).data('ctx').ListData.Row;
001.png
001.png (48.14 KiB) Viewed 4004 times

Re: Send Total of Child List to Parent List

Posted: 17 Mar 2017
by Dmitry Kozlov
Hi,
Most likely, you retrieve an incorrect list view. Try to open the form in a browser, expand the browser console (F12), and type in the Console tab:
fd.relatedItems(0).data('ctx').ListTitle

Then change index in the 'relatedItems' to find the correct view.

Re: Send Total of Child List to Parent List

Posted: 17 Mar 2017
by Cloud.Ed
This form opens in Model and the code fails. On a whim I set the form to open normal and the code works. Can you help?

Re: Send Total of Child List to Parent List

Posted: 20 Mar 2017
by Dmitry Kozlov
Are you sure that you put the code into the right form? I've just tested the following scenario in both, dialog and non-dialog modes, and everywhere it worked fine:
1. Inserted the code into the form:
alert(fd.relatedItems(0).data('ctx').ListTitle);
2. Tested in a dialog.
3. Tested in the non-dialog mode.