Calculation is wrong on Click event
Hi all,
when I use this script the result is wrong. The source field is a calculated field, for example 1,000.00 € and the result in the target field is 1.00 €
//Calculate Kosten interner IT Aufwand
var total = 0;
var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
var currencyIT = item['Kosten'];
var numberIT = parseFloat(currencyIT.replace(/[^0-9,-]+/g,"").replace(",","."));
total += numberIT;
total_overall += numberIT;
});
fd.field('Kosten_x0020_IT').value(parseFloat(total.toFixed(2)));
Please help.
Best wishes
Tom
when I use this script the result is wrong. The source field is a calculated field, for example 1,000.00 € and the result in the target field is 1.00 €
//Calculate Kosten interner IT Aufwand
var total = 0;
var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
var currencyIT = item['Kosten'];
var numberIT = parseFloat(currencyIT.replace(/[^0-9,-]+/g,"").replace(",","."));
total += numberIT;
total_overall += numberIT;
});
fd.field('Kosten_x0020_IT').value(parseFloat(total.toFixed(2)));
Please help.
Best wishes
Tom
Hello Tom,
Try to remove ',' from the string. I've updated the code:
Try to remove ',' from the string. I've updated the code:
Code: Select all
//Calculate Kosten interner IT Aufwand
var total = 0;
var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
var currencyIT = item['Kosten'];
//updated line
var numberIT = parseFloat(currencyIT.replace(/[^0-9,-]+/g,"").replace(",",""));
total += numberIT;
total_overall += numberIT;
});
fd.field('Kosten_x0020_IT').value(parseFloat(total.toFixed(2)));
Hello Mnikitina,
many thanks. So i can solve the problem. But I have an second error. When I add a new item in the related items and I use the OnClick function the value is doubled. But when I save first and open the form again and the use the OnClick function the result is correct.
var total_overall = 0;
//Calculate Kosten interner IT Aufwand
var total = 0;
var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
var currencyIT = item['Kosten'];
var numberIT = parseFloat(currencyIT.replace(/[^0-9,-]+/g,"").replace(",",""));
total += numberIT;
total_overall += numberIT;
});
fd.field('Kosten_x0020_IT').value(parseFloat(total.toFixed(2)).toLocaleString());
Many thanks for you assistance
Tom
many thanks. So i can solve the problem. But I have an second error. When I add a new item in the related items and I use the OnClick function the value is doubled. But when I save first and open the form again and the use the OnClick function the result is correct.
var total_overall = 0;
//Calculate Kosten interner IT Aufwand
var total = 0;
var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
var currencyIT = item['Kosten'];
var numberIT = parseFloat(currencyIT.replace(/[^0-9,-]+/g,"").replace(",",""));
total += numberIT;
total_overall += numberIT;
});
fd.field('Kosten_x0020_IT').value(parseFloat(total.toFixed(2)).toLocaleString());
Many thanks for you assistance
Tom
-
- Information
-
Who is online
Users browsing this forum: No registered users and 10 guests