# How can a model-driven JavaScript command read a saved row instead of unsaved form values?

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

## Also asked as

- How do I use PrimaryControl for a main-form command that reads Dataverse?
- How can a main-form button check a saved account value safely?

For a JavaScript command on a model-driven **main form**, configure `PrimaryControl` and use it directly as the form context. Capture the current table and row ID, then use `Xrm.WebApi.retrieveRecord` to read saved Dataverse data under the signed-in user's access.

In an isolated Account form with a published web resource, capture `primaryControl.data.entity.getId()` before awaiting a result and strip any braces. If no row ID is present, ask the user to save before checking. For a saved account, `Xrm.WebApi.retrieveRecord("account", id, "?$select=creditonhold")` requests only the required column. A denied, missing or failed read should show an unavailable result. A grid command needs its own selection context and must handle its selection count.

A form event handler receives execution context, while this command receives form context directly. Avoid using retained form state after an asynchronous read. Keep the result associated with the captured ID and suppress obsolete responses where the host workflow requires it. Check the actual command's save behavior and display a saved value as a snapshot for the user.

Test an unsaved row, a saved row with unsaved edits, missing read privileges and navigation while a read is pending. A later business operation must enforce its own permission and current-state checks.

[Form and grid command parameters](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/pass-data-page-parameter-ribbon-actions) · [retrieveRecord](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrieverecord) · [Client API execution context](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-execution-context)

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)
