Problem with calculation : JS vs variable

I'm trying to make a very simple calculation.

a variable gets me the correct result, while the same JS code does not work

Any idea ?

Where does it get it wrong? I see a linting issue where you have Math.abs(balance) instead of Math.abs(balance_lignes) (I assume). Is that the issue?

Hi Jg,

Thanks for your reply.
As a matter of fact, I just changed the variable name, but I did not change it here because it does not have anything to see with the issue.

So that's not it.

What does the JS get you? Maybe I’m missing it in the screenshot, but I don’t see the incorrect result so I’m not sure what we are troubleshooting.

HI jg,

As a matter of fact, the problem is more intricate.
In the end, the JS code does work.

However, the underlying data is wrong. Let me explain.

my table is as follow, with two sums on the footer.
It relies on a variable array ('currentLignesList')
Since I cannot access the 'sum' fields in the table, I had to reconstitute in two text boxes ('text1' and 'text2', calculated also from the variable array).

In my script, I modify the underlying array ('currentLignesList') with 'setIn'
It looks like the table and text boxes update accordingly, BUT in reality, the JS returns a calculation based on the values BEFORE change (as if nothing happened - hence my impression JS did not work).

Gotcha - so it is a synchronous execution challenge.