Calculate Total of related item column
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Hello,
I think you can find the necessary code in this topic - viewtopic.php?f=1&t=592&p=4049&hilit=fd ... Data#p4049
Tell me if this works for you or not.
I think you can find the necessary code in this topic - viewtopic.php?f=1&t=592&p=4049&hilit=fd ... Data#p4049
Tell me if this works for you or not.
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Glad to have helped, you are welcome!
Cheers
Hi Nikita,
For some reason the list items are being counted twice. Here is my code
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
subTotal += parseFloat(item['QtyRequested.'] * item['UnitCost.']);
});
When I try fd.relatedItems().length in the console it displays '1' although it is empty.
Can you help?
For some reason the list items are being counted twice. Here is my code
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
subTotal += parseFloat(item['QtyRequested.'] * item['UnitCost.']);
});
When I try fd.relatedItems().length in the console it displays '1' although it is empty.
Can you help?
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Okay, let's try to figure out why this might happen. The code you have works fine for me. Try using this code from the console and let us know the results:
This will show you how many rows there are in the table. Then you can add this to your code, to see the calculations happening:
fd.relatedItems().length simply shows that you have one Related items field on your form, even if it is empty.
Code: Select all
fd.relatedItems(0).data('ctx').ListData.Row.length
Code: Select all
rows.forEach(function(item) {
subTotal += parseFloat(item['QtyRequested.'] * item['UnitCost.']);
console.log(subTotal);
});
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Okay, it seems like there is something weird going on with the list, but we haven't managed to recreate this bug.
So, for now, I can recommend changing your code to this, it will filter out all items with repeating IDs:
So, for now, I can recommend changing your code to this, it will filter out all items with repeating IDs:
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);
}
});
singles.forEach(function(item) {
subTotal += parseFloat(item['QtyRequested.'] * item['UnitCost.']);
});
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests