Related item count - Quick Edit

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

03 Jul 2019

Related items in quick edit:

Using the script below, before adding a new row to the related items, it loops the correct number of times. Once I add a new related item it loops 1 extra time returning the last item twice. Please tell me I'm crazy.

var rows = fd.relatedItems(5).data('ctx').ListData.Row;
var myCost = ''
var myTotal = 0.00
var myCount = 0.00
if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) {
myCost = rows.Cost;
myCost = myCost.replace('$', '')
myCost = myCost.replace(',', '')
myCount = rows.Count;
myCost = parseFloat(myCost) * parseFloat(myCount);
myTotal = parseFloat(myTotal) + parseFloat(myCost);
}
fd.field('TotalCostM').value(myTotal);
} else {
fd.field('TotalCostM').value('');
}

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

04 Jul 2019

Dear Tony,
Yeah, you are not seeing it... :D Unfortunately, this is a known bug for newly added items and one of the most common questions on the forum (although still quite rare). We've not managed to find the reason for it, but we've found a relatively simple solution - you can filter out duplicates with the following code:

Code: Select all

var rows = fd.relatedItems(0).data('ctx').ListData.Row;
var dupes = {};
var singles = [];

$.each(rows, function(i, el) {
    if (!dupes[el.ID]) {
        dupes[el.ID] = true;
        singles.push(el);
    }
});

//do the calculations for singles variable, instead of rows
This should help, but let me know how it goes!
Cheers

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

08 Jul 2019

Got it. Back on track!

Thank you.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests