Write JavaScript Form Events with Execution Context: Series 5

Write JavaScript Form Events with Execution Context: Series 5

Use formContext, event arguments, and supported client APIs for maintainable model-driven app scripting.

Implementation guide

Pass executionContext to every registered event handler and obtain formContext with executionContext.getFormContext(). Use formContext.getAttribute and getControl rather than deprecated global Xrm.Page references. Register OnLoad, OnChange, and OnSave handlers deliberately, and avoid duplicate handler registration. Use setValue for client-side updates and fireOnChange only when downstream handlers should run. For asynchronous work, use supported APIs and return or await promises only where the event contract supports them. Validate the script in the actual form and app, including quick create and mobile experiences if those are in scope.

Developer checklist

  • Confirm the message, table, execution stage, and security context.
  • Use supported SDK or Web API contracts and verify metadata names.
  • Handle errors explicitly and avoid unsafe retry behavior.
  • Trace useful diagnostics without logging secrets or sensitive data.
  • Test with least-privilege users in a non-production environment.