# How do I register a model-driven form handler and get the correct form context?

Exam: AB-400 — Power Platform Developer Associate
Knowledge domain: Extend the user experience (25–30%)
Updated: 2026-11-25T06:47:18.511329+00:00
HTML: https://learningpathx.com/faq/AB-400/ab400-model-driven-form-event-context.html

## Also asked as

- Why is my model-driven OnLoad or OnChange handler missing its execution context?
- How do I attach and test a JavaScript warning on a model-driven form?

Add a JavaScript web resource as a library on the target model-driven form. Register its function for form OnLoad and the relevant column's OnChange, enable **Pass execution context as first parameter**, and obtain the current form with `executionContext.getFormContext()`.

Use the column's logical name with `getAttribute` and guard against a missing attribute on alternate forms. Attributes hold data. Controls present it. For a credit-hold warning, check the current form-buffer value and set or clear a notification using one stable ID. OnLoad sets the initial message, while OnChange refreshes it after a user edit.

If you register with `addOnChange` instead, the platform supplies execution context. Keep the registration repeatable and use `removeOnChange` when removing the named handler. Calling `setValue` alone leaves OnChange handlers uncalled. Invoke `fireOnChange` deliberately when a dependent behavior should run, and prevent a loop between handlers.

Publish the web resource and form. Test the held, cleared and missing-column cases on the intended forms. If the function never runs, check the selected form, published library and function name before debugging the handler. During cleanup, remove temporary handler registrations before deleting their dependency, and keep any library that still has consumers.

[Client API form context](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-form-context) · [Column OnChange event](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/events/attribute-onchange) · [Form notification API](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/formcontext-ui/setformnotification)

Source: [AB-400: Client Scripting and Commands in Model-Driven Apps](https://learningpathx.com/news/ab-400-client-scripting-and-commands-in-model-driven-apps.html)
