Dynamic FormCalc Eval

Eval(source) compiles a dynamically supplied calculation with the native FormCalc compiler and executes 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 are available 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 read variables or functions declared by the calling calculation

The current field, relative form objects, $form, $host and $event remain available; Eval(null) returns null, and other scalar arguments become source text

Inside a SOM predicate, the candidate supplies 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, while Eval("var secret=2 secret+1") returns 3

Transactions and replay

A first use of a source suspends execution so the native compiler can produce its JavaScript; the host restores the pre-event script state, supplies the compiled response and retries the calculation

Recorded transport and locale responses are consumed during retry, so a nested compilation does not repeat external transport callbacks

Only the final successful evaluation enters 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 preserves 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 alongside configured script input, operation, memory, stack, journal and elapsed time limits

A configured stack or elapsed time limit can fail before the dedicated nesting or request bound; compilation retries share the event deadline

A custom JavaScript evaluator cannot service native dynamic compilation requests; use the shipped QuickJS execution path

Related APIs

HPDFXFACompileFormCalcEvent, HPDFXFAExecuteJavaScriptEvent, FormCalc Functions and Interactive XFA Runtime