Related Items Sum

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
jennifer_little
Posts: 10
Joined: Fri Mar 03, 2017

23 Mar 2017

Hi Dmitry,

I have created a few test lists to strip back what I was doing. I have attached the findings from running f12.

Thanks

Jennifer
Attachments
SnipImage.JPG
SnipImage.JPG (36.09 KiB) Viewed 4836 times

jennifer_little
Posts: 10
Joined: Fri Mar 03, 2017

23 Mar 2017

Please see the parent list with the project cost field and the child list with the costs that I want to add up.

Thanks

Jennifer
Attachments
image 2.png
image 2.png (9.18 KiB) Viewed 4836 times

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

23 Mar 2017

Please, use the following code:

Code: Select all

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

jennifer_little
Posts: 10
Joined: Fri Mar 03, 2017

23 Mar 2017

Thanks! I got this to work in my sandbox. I am wanting to do the calculation on the Display Form. I can get the pop up with the total but when it comes to inputting the total into a field it doesn't work. Is this because its the Display View?

Thanks

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

24 Mar 2017

You cannot update a field in a Display form. But you can replace its display value:
fd.field('FieldName'),control()._el().html(calculatedValue);

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests