Related item count - Quick Edit
Posted: 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('');
}
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('');
}