Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Help: Divide by Zero Errors

Avatar

Level 2
Hi, can someone please advise me on how to avoid script failure alerts (like the one below), which are generated because certain calculations are being performed before any positive value has yet been set in a numeric field?



Here is an example of the calculation:



--- form1.SF_CalculationTable.acview[0]::calculate - (FormCalc, client) --



(ac[0] / tr[0]) * 100



Error example:



Script failed (language is formcalc; context is

xfa[0].form[0].form1[0].SF_CalculationTable[0].acview[0])

script=(ac[0] / tr[0]) * 100

Error: arithmetic over/underflow.



update: it appears these erros are "divide by zero" errors.

So my questions are,

(1) would I put any javascript (to override the zeros) on the "validate" event or the "calculate" event, and on which of the three fields in question, acview[0] (the result), tr[0] (the denominator) or ac[0] (the numerator). and...



(2) What might that javascript look like?



--

Harry
1 Reply

Avatar

Level 2

Your error message indicates your script is being executed as FormCalc, not JavaScript.

If you're using FormCalc try using an If statment to test for zero/null.

if (tr>0) then (ac/tr)*100 endif