Related item count - Quick Edit
-
- Posts: 21
- Joined: Sun Feb 24, 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('');
}
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('');
}
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Tony,
Yeah, you are not seeing it... 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:
This should help, but let me know how it goes!
Yeah, you are not seeing it... 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
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 7 guests