Almost everything a form script does goes through one object: formContext. Every registered event handler receives it as part of the execution context, and it’s your entry point to reading and manipulating the form.
Getting the form context
function onLoad(executionContext) {
var formContext = executionContext.getFormContext();
}
This pattern — accepting executionContext as the first parameter and immediately pulling formContext from it — is the standard first line of nearly every modern form script function.
Key areas of the form context
formContext.getAttribute("fieldname")— access a specific column’s data:.getValue(),.setValue(),.setRequiredLevel(),.fireOnChange().formContext.getControl("fieldname")— access the UI control itself:.setVisible(),.setDisabled(),.setNotification().formContext.ui— form-level UI: the ribbon, tabs, form notifications, and the form’s current mode (create vs. update).formContext.data— the record’s data as a whole:.save(),.refresh(), and.entityfor entity-level metadata like the record’s ID and whether it’s dirty (unsaved changes).
Legacy Xrm.Page
Older code and tutorials often use Xrm.Page instead of executionContext.getFormContext(). It still works in most cases but is deprecated — new code should always use the execution-context pattern, since Xrm.Page doesn’t reliably work in every context (like certain multi-form scenarios) and Microsoft has signaled it will eventually be removed.