PL-400 study materials
PL-400 study resources

PL-400: Extend the user experience

PL-400 · Work through your exam, one topic at a time.

All guide sections

Extend the user experience

The client API

Modern model-driven scripts use executionContext.getFormContext() (or the PrimaryControl parameter) instead of the deprecated Xrm.Page. From the form context reach attributes with getAttribute for values and controls with getControl for visibility, disabled state and labels. Register OnLoad and OnSave handlers in the form designer; OnChange handlers added with addOnChange must be re-added on every load, whereas handlers registered in the designer persist with the form.

Notifications and save control

control.setNotification(message, uniqueId) shows a field-level error; formContext.ui.setFormNotification(message, level, uniqueId) shows a form banner. Always pass a stable unique id so the message can be cleared, and avoid alert(), which is blocked in many hosts. executionContext.getEventArgs().getSaveMode() distinguishes save, save and close, and deactivate; preventDefault() cancels the save only for modes that allow it.

Beyond the form

Command bar buttons are configured with the command designer or Ribbon Workbench, and JavaScript commands receive the PrimaryControl. PCF controls replace a field or an entire dataset with TypeScript/React UI and ship inside solutions. Custom pages host canvas content inside the app. Business process flows guide stages; legacy dialogs are deprecated and are replaced with a custom page plus a flow.

Traps

  • A handler registered twice (designer plus addOnChange) fires twice.
  • Xrm.Page is deprecated and fails in newer hosts.
  • Blocking on Xrm.WebApi calls makes forms slow; use callbacks and disable the control while waiting.
  • Changing the unique id on every call leaves duplicate banners.
  • Never enforce security in script - browser code is bypassable through the Web API.

Rule of thumb

Validation that must hold for every write path belongs server-side (an Entity-scope business rule or a plug-in). Form script is for user experience: show/hide, enable/disable, messages, and navigation orchestration.