A model-driven form script calls formContext.getAttribute("revenue").addOnChange(recalc) inside a handler registered with formContext.data.addOnLoad. Users report that after they save the record, recalc runs twice for every change, and three times after a second save. What explains this?
Select an answer to reveal the explanation.
Short Explanation
You're signing the same name onto the guest list every time the page refreshes, so the host calls it out twice, then three times. Register your OnChange handler once, in the form OnLoad or the designer, not in an event that keeps firing after each save.
Full Explanation
The form data OnLoad event, managed through formContext.data.addOnLoad, fires on the initial page load, when data is explicitly refreshed with formContext.data.refresh, and when the data is refreshed after a save with changes. Code that calls addOnChange inside that handler therefore registers the same function again on every refresh, and the column's OnChange event invokes each registration, which matches the growing count users see. The fix is to register column handlers once, in the form OnLoad event or declaratively in the form designer, or to call removeOnChange before adding the handler. Business rules do not invoke script handlers registered on a column, so they do not multiply calls. Registrations live in the current form session; they are not persisted across browser sessions or cached between visits. Programmatic setValue does not fire the OnChange event; only a user change or an explicit fireOnChange call does, so a handler that sets the column it listens to does not loop by itself. Exam caveat: code-based registration is useful for conditional or dynamic handlers, but it puts the burden of avoiding duplicates on the developer, which designer registration avoids. Operational check: add a counter or console message to recalc, save the record twice, and confirm a single call per change after moving the registration.