Dynamic FormCalc Eval
Eval(source) compiles a dynamically supplied calculation with the native FormCalc compiler and runs it through the general event host when EnableJavaScript is enabled
The source can contain expressions, conditionals, loops, variable declarations, locally declared functions and field mutations; the final expression is the result, and built-in names are case-insensitive
var source = "target + other"
target = Eval(source)
target = Eval("var n=2 for i=1 upto 4 do n=n*i endfor n")
Scope and objects
Ref and reference assignment work inside evaluated calculations, using the same explicit handle and ordinary value-copy rules as the calling event
Each evaluated calculation has its own variables and functions; it cannot see variables or functions declared by the calling calculation
The current field, relative form objects, $form, $host and $event stay available; Eval(null) returns null, and other scalar arguments become source text
Inside a SOM predicate, the candidate provides the current field or subform context, and nested Eval inherits that context
For example, var secret=9 Eval("secret+1") fails when there is no form object named secret, whilst Eval("var secret=2 secret+1") returns 3
Transactions and replay
A first use of a source pauses execution so the native compiler can produce its JavaScript; the host restores the pre-event script state, provides the compiled response and retries the calculation
Recorded transport and locale responses are consumed during retry, sparing a nested compilation from repeating external transport callbacks
Only the final successful evaluation reaches the script journal; syntax errors, runtime errors and budget failures restore field values, instance state and script state through the runtime transaction
Eval also works inside actual calculated fields and validation scripts; SaveToBytes keeps committed document values
Budgets
Each event allows at most 64 distinct dynamic sources, eight nested Eval calls and 2 MiB of aggregate dynamic source plus compiled response bytes; these bounds apply on top of configured script input, operation, memory, stack, journal and elapsed time limits
A configured stack or elapsed time limit may fail ahead of the dedicated nesting or request bound; compilation retries share the event deadline
A custom JavaScript evaluator cannot serve native dynamic compilation requests; use the bundled QuickJS execution path
Related APIs
HPDFXFACompileFormCalcEvent, HPDFXFAExecuteJavaScriptEvent, FormCalc Functions and Interactive XFA Runtime