Calculate related item Not a Number error
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear TWendt,
As I said, I don't need screenshots of the error or of the code - you can comment it out for now, it doesn't matter.
What I need, is for you to copy this text:
And open the form, open browser's console and paste it there, and press Enter.
Then, expand the object, so we can see the properties it has and how the information is stored in the column that interests you, like this:
As I said, I don't need screenshots of the error or of the code - you can comment it out for now, it doesn't matter.
What I need, is for you to copy this text:
Code: Select all
fd.relatedItems(6).data('ctx').ListData.Row[0];
Then, expand the object, so we can see the properties it has and how the information is stored in the column that interests you, like this:
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Tom,
Thank you for this! Now, please, try the following in console as well, see what it gives you:
For this test to be more informative, you can also try changing Kosten in the first row of the table from 1.000,00 euro to 1.000,01 euro (or some other value with cents).
Thank you for this! Now, please, try the following in console as well, see what it gives you:
Code: Select all
var currency = fd.relatedItems(6).data('ctx').ListData.Row[0].Kosten;
var number1 = parseFloat(currency.replace(/[^0-9,-]+/g,""));
var number2 = parseFloat(currency.replace(/[^0-9,-]+/g,"").replace(",","."));
console.log(number1 );
console.log(number2);
Cheers
Dear Nikita,
here is the modified script. Now the NaN error dows not occur.
//Calculate Kosten interner IT Aufwand
var total = 0;
var currency = fd.relatedItems(6).data('ctx').ListData.Row[0].Kosten;
var number1 = parseFloat(currency.replace(/[^0-9,-]+/g,""));
var number2 = parseFloat(currency.replace(/[^0-9,-]+/g,"").replace(",","."));
console.log(number1 );
console.log(number2);
//var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item['Kosten.'])
total_overall += parseFloat(item['Kosten.'])
});
fd.field('Kosten_x0020_IT').value(Number(total.toFixed(2)).toLocaleString("de-DE", {style: "currency", currency: "EUR"}) + ' €');
But the 2000 € will not be added.
Best wishes
Tom
here is the modified script. Now the NaN error dows not occur.
//Calculate Kosten interner IT Aufwand
var total = 0;
var currency = fd.relatedItems(6).data('ctx').ListData.Row[0].Kosten;
var number1 = parseFloat(currency.replace(/[^0-9,-]+/g,""));
var number2 = parseFloat(currency.replace(/[^0-9,-]+/g,"").replace(",","."));
console.log(number1 );
console.log(number2);
//var rows = fd.relatedItems(6).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item['Kosten.'])
total_overall += parseFloat(item['Kosten.'])
});
fd.field('Kosten_x0020_IT').value(Number(total.toFixed(2)).toLocaleString("de-DE", {style: "currency", currency: "EUR"}) + ' €');
But the 2000 € will not be added.
Best wishes
Tom
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Tom,
I've previously asked to run the commands in console as well, not modify anything in the code yet. It's better to test everything first, and when we're certain that it will work - apply it to the code.
Right now, I'm still not certain that this will works, so I've asked you to modify value in the row from 1.000,00 to 1.000,01 and run the console commands like you did before:
So it looks like this, and we can check the result:
I've previously asked to run the commands in console as well, not modify anything in the code yet. It's better to test everything first, and when we're certain that it will work - apply it to the code.
Right now, I'm still not certain that this will works, so I've asked you to modify value in the row from 1.000,00 to 1.000,01 and run the console commands like you did before:
Code: Select all
var currency = fd.relatedItems(6).data('ctx').ListData.Row[0].Kosten;
var number1 = parseFloat(currency.replace(/[^0-9,-]+/g,""));
var number2 = parseFloat(currency.replace(/[^0-9,-]+/g,"").replace(",","."));
console.log(number1);
console.log(number2);
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Tom,
Okay, so I think you should be able to run the following code, please, try it*:
*code has been fixed after feedback
Okay, so I think you should be able to run the following code, please, try it*:
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'];
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("de-DE", {style: "currency", currency: "EUR"}) + ' €');
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Oh, yes, my bad! I will fix it in the previous post as well.
Glad to hear that it works. It's always best to investigate such issues via console first, and when you get to the working variant - implement it in the global code. Just allows to see the problems before they block all the progress.
Let us know if you need anything else - we'll be happy to help!
Glad to hear that it works. It's always best to investigate such issues via console first, and when you get to the working variant - implement it in the global code. Just allows to see the problems before they block all the progress.
Let us know if you need anything else - we'll be happy to help!
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 9 guests