Skip to main content
edembers
Participant
April 9, 2018
Question

Force recalculation

  • April 9, 2018
  • 1 reply
  • 2512 views

I‘ve got a form with fields, with Subtotal and Total. The calculation order is correct, this form works perfectly.

I‘ve got another similar form that sometimes gets added to the first, with Subtotal as the last field. This works perfectly too. But when added to the first form, the Total doesn‘t work correctly across all the sheets, as the calculation order is no longer correct - the Total on the first sheet is calculated before the Subtotals on subsequent sheets.

One solution would be to stipulate that they MUST paste the extra sheets BEFORE the first sheet, then reoder them, so that Total is always calculated last. But that creates other problems.

A better solution would be to force a double recalculation whenever a subtotal is changed, using Validation. The first time would calculate all subtotals correctly, the second time would then get the correct answer in the Total. I thought this.calculateNow() should do it, or doc.calculateNow(), but this doesn‘t work. Perhaps there is a command to abandon and restart the calculation if the current field (a Subtotal field) gets changed? Can someone help me?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
April 9, 2018

The "calculateNow()" function does force recalculation. If it is not working for getting your field up to date, then something else is going on that is preventing it. Try running it from the console window after the other calculations have finished.

The problem may be that at the time the subtotal validation happens, the needed field values haven't yet been committed.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often