# Apply business logic in model-driven apps by using client scripting — Practice reading

Exam: AB-400 — Power Platform Developer Associate
Knowledge domain: Extend the user experience (25–30%)
HTML: https://learningpathx.com/learning-path/AB-400/learn/523

This public learning practice includes correct answers and existing explanations. Reading does not save progress or create a test.

## Question 1

Type: single\_choice
Knowledge point: Build code that targets the Client API object model

A developer is writing a shared validation function for a model-driven app targeting version 9.0 or later. The function expects form context. A main-form ribbon command passes the CrmParameter value PrimaryControl to one JavaScript wrapper. An editable-grid row event passes execution context to another wrapper. Validation must operate on the form or row that triggered the action. How should the wrappers obtain the context passed to the shared function?

### Options

**A**

Pass PrimaryControl directly from the command wrapper; pass executionContext.getFormContext() from the grid-event wrapper.

**B**

Call getFormContext() on the received argument in both wrappers, then pass the returned object.

**C**

Pass the received argument directly from both wrappers.

**D**

Pass Xrm.Page from both wrappers.

Correct answer: A

### Explanation

The wrappers receive different kinds of arguments. The ribbon command's PrimaryControl argument already supplies form context, while the editable-grid event's execution context exposes the relevant row context through getFormContext(). Mapping each argument correctly lets the shared function operate on the triggering form or row. Calling getFormContext() in both wrappers incorrectly treats PrimaryControl as execution context. Sources: [Form context](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-form-context) and [Ribbon action parameters](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/pass-data-page-parameter-ribbon-actions).

## Question 2

Type: single\_choice
Knowledge point: Build code that targets the Client API object model

An OnLoad script already receives valid form context and runs synchronously on two account forms. The Full form displays new\_reviewnote through two controls. The Summary form omits the column, and formContext.getAttribute('new\_reviewnote') returns null there. When the column is present, the script must set its value to 'Review pending' and hide all its visual representations. Unrelated controls must retain their existing visibility. When the column is absent, the script must finish without error or data changes. Which implementation plan meets these requirements?

### Options

**A**

Retrieve new\_reviewnote with formContext.getAttribute. If the attribute is absent, return; otherwise set its value and hide the first control in attribute.controls.

**B**

Retrieve new\_reviewnote with formContext.getAttribute. If the attribute is absent, return; otherwise set its value and hide every control in formContext.ui.controls.

**C**

Retrieve new\_reviewnote with formContext.getAttribute, set its value, and hide every control in attribute.controls without checking whether the attribute is present.

**D**

Retrieve new\_reviewnote with formContext.getAttribute. If the attribute is absent, return; otherwise set its value and hide every control in attribute.controls.

Correct answer: D

### Explanation

The column value belongs to its attribute, while the attribute's controls collection identifies its visual representations. The script must first handle the absent attribute, then change the value and hide all controls bound to that attribute. Guarding the attribute but hiding only its first control leaves another representation visible. Hiding the form's entire controls collection also affects unrelated controls. Sources: [Form-context collections](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-form-context) and [Client API object model](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/understand-clientapi-object-model).

## Question 3

Type: single\_choice
Knowledge point: Build code that targets the Client API object model

A model-driven form's OnLoad handler obtains form context and a target attribute, starts a background request for a suggested value, and returns. Its completion callback writes through the cached attribute. In failing runs, the request and response parsing succeed, but the user has navigated to another record or closed the form before the callback runs. The suggestion must be applied when its originating form is still active, and otherwise discarded. Which change addresses the failure?

### Options

**A**

Check that the target attribute exists before starting the request; use the cached attribute to apply each successful result.

**B**

After the request succeeds, obtain form context again from the saved execution context and apply the result without further checks.

**C**

After the request succeeds, check that the originating form and record are still active and that the target attribute is available; apply the result only when those checks pass.

**D**

Add request-error handling and continue to apply successful responses through the cached attribute.

Correct answer: C

### Explanation

The successful request does not establish that the original form remains a valid target. Context behavior is guaranteed during the event, and navigation can invalidate assumptions made before asynchronous work completes. The completion logic should therefore verify the originating form and record and confirm that the target attribute is available before applying the result. Obtaining form context again from a saved execution context does not itself validate those conditions. This is a defensive application of Microsoft's [asynchronous context guidance](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-execution-context), not an extension of the context's guaranteed lifetime.

## Question 4

Type: single\_choice
Knowledge point: Build code that targets the Client API object model

A developer creates an authenticated standalone HTML web resource in Dataverse. It is opened directly in a top-level browser window, has no containing model-driven form, and window.Xrm is undefined. The resource needs organization and current-user information for the session. Which approach should the developer use to obtain global context?

### Options

**A**

Call Xrm.Utility.getGlobalContext() directly in the web resource's own window.

**B**

Include a reference to ClientGlobalContext.js.aspx in the web resource, then call GetGlobalContext().

**C**

Call parent.Xrm.Utility.getGlobalContext() from the web resource.

**D**

Treat the DOMContentLoaded event argument as execution context and call its getFormContext() method.

Correct answer: B

### Explanation

A standalone HTML web resource uses ClientGlobalContext.js.aspx and GetGlobalContext() to access organization and user context. Xrm.Utility.getGlobalContext() is the form-hosted route, but this resource has no Xrm object in its window. Its top-level parent does not supply a containing form, and a DOM load event does not supply a model-driven execution context. Source: [Global context for standalone HTML web resources](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-xrm).

## Question 5

Type: single\_choice
Knowledge point: Determine an event handler registration approach

A developer registers Acme.Account.onLoad for the OnLoad event of an Account main form in a model-driven app. The browser loads the library and enters the function, but execution fails at getFormContext(). At function entry, the debugger shows that executionContext is undefined.

The handler begins:

```javascript
Acme.Account.onLoad = function (executionContext) {
    const formContext = executionContext.getFormContext();
};
```

The form designer shows:

```text
Library: acme_account.js
Function: Acme.Account.onLoad
Enabled: Yes
Pass execution context as first parameter: No
Additional parameters: none
```

Which registration change resolves the failure without changing the handler code?

### Options

**A**

Set the handler's additional parameter to the literal string 'executionContext'.

**B**

Select Pass execution context as first parameter for the registered handler.

**C**

Move the handler to OnSave while retaining its parameter settings.

**D**

Move the handler earlier in the OnLoad event-handler list.

Correct answer: B

### Explanation

The library and function resolve because execution reaches the handler. The missing first argument matches the unchecked context-passing setting. Selecting Pass execution context as first parameter supplies the event's execution-context object to the existing function. A literal additional parameter cannot substitute for that object. [Microsoft Learn: Client API execution context](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-execution-context).

## Question 6

Type: single\_choice
Knowledge point: Determine an event handler registration approach

An Account form in a model-driven app has a controller that lives for one open form session. Its attribute variable references the Quantity column. A calculation feature can be enabled and disabled repeatedly, and initialization can run again while the feature remains enabled.

The controller currently uses:

```javascript
function enable() {
    attribute.addOnChange(function (context) {
        recalculate(context);
    });
}

function disable() {
    attribute.removeOnChange(function (context) {
        recalculate(context);
    });
}
```

After repeated initialization, one Quantity change causes several recalculations. Disabling the feature leaves callbacks active. Which refactoring prevents accumulated subscriptions and detaches the handler when disabled?

### Options

**A**

Replace the stored handler with a new wrapper on each initialization and add it; on disable, remove the stored handler and clear the flag.

**B**

Use a per-form subscription flag to add one anonymous handler; on disable, remove a new anonymous handler with the same body and clear the flag.

**C**

Use a per-form subscription flag to add a stored handler only when absent; on disable, remove the stored handler and clear the flag.

**D**

Use a per-form subscription flag to add a stored handler only when absent; on disable, clear the flag without removing the handler.

Correct answer: C

### Explanation

Repeated initialization must not create additional subscriptions, and disabling must remove the subscription that was actually added. A per-form flag controls when to add the handler, while a stored function reference identifies it for removal. A newly created function with identical code is a different JavaScript function object. [Microsoft Learn: addOnChange](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/attributes/addonchange) describes conditional registration and function-reference parameters; [Events in forms and grids](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/events-forms-grids) identifies the addOnChange and removeOnChange methods.

## Question 7

Type: single\_choice
Knowledge point: Determine an event handler registration approach

On an Account main form in a model-driven app, an existing Quantity OnChange handler reads the current Quantity and updates a calculated display. User edits run the handler successfully. Quantity is 4 before the button is clicked.

The button currently runs:

```javascript
const quantity = formContext.getAttribute("new_quantity");
quantity.setValue(12);
```

After that click, the Quantity control shows 12, but the calculated display remains unchanged. Which sequence should replace the button code so that the existing OnChange handler evaluates the new Quantity during the same click?

### Options

**A**

Call quantity.setValue(12), then call quantity.fireOnChange().

**B**

Call quantity.setValue(12) twice.

**C**

Call quantity.fireOnChange(), then call quantity.setValue(12).

**D**

Register the calculation handler again with addOnChange, then call quantity.setValue(12).

Correct answer: A

### Explanation

User edits already run the calculation handler, establishing that it is registered. The replacement button sequence starts with Quantity at 4\. Programmatic setValue changes the value without raising OnChange. Calling fireOnChange after assigning 12 runs the registered synchronous handler when the new value is available. [Microsoft Learn: Column OnChange event](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/events/attribute-onchange).

## Question 8

Type: single\_choice
Knowledge point: Determine an event handler registration approach

A model-driven app has Async onSave handler enabled. On an Account main form, one OnSave handler starts two independent checks:

```javascript
function onSave(executionContext) {
    const accountCheck = checkAccount();
    const termsCheck = checkTerms();
}
```

Each helper returns a promise that fulfills when its check completes. In this test, both checks succeed within two seconds, but they can finish at different times. The save currently proceeds while the checks are still running. Which change makes the platform wait for both checks before proceeding with this save?

### Options

**A**

Return the array \[accountCheck, termsCheck\] from onSave.

**B**

Return Promise.race(\[accountCheck, termsCheck\]) from onSave.

**C**

Call Promise.all(\[accountCheck, termsCheck\]) inside onSave, then return no value.

**D**

Return Promise.all(\[accountCheck, termsCheck\]) from onSave.

Correct answer: D

### Explanation

The Account form and enabled Async onSave handler setting provide the applicable event contract. The platform must receive a promise representing both checks. Returning Promise.all combines their successful completion into the single promise accepted from this handler. Starting the aggregate without returning it leaves the platform without that wait condition; Promise.race can settle before the slower check finishes. [Microsoft Learn: Form OnSave event](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/events/form-onsave).

## Question 9

Type: single\_choice
Knowledge point: Determine an event handler registration approach

An Account main form in a model-driven app has an OnLoad handler that displays instructions and an OnSave handler that validates data. Both work when editing one record. In bulk edit, neither handler is called. The libraries and function names are correct, both handlers are enabled, and both registrations pass execution context. Which Form XML configuration and expected behavior are supported for bulk edit?

### Options

**A**

Set BehaviorInBulkEditForm to Enabled on the OnLoad event element; expect both handlers to run in bulk edit.

**B**

Set BehaviorInBulkEditForm to Enabled on the OnLoad event element; expect OnLoad to run and OnSave to remain inactive in bulk edit.

**C**

Set BehaviorInBulkEditForm to Enabled on the OnSave event element; expect OnSave to run and OnLoad to remain inactive in bulk edit.

**D**

Set BehaviorInBulkEditForm to Enabled on both event elements; expect both handlers to run in bulk edit.

Correct answer: B

### Explanation

Correct registration does not override bulk-edit event behavior. Event handlers are not called in bulk edit by default. The documented Form XML exception sets BehaviorInBulkEditForm to Enabled on the relevant event element and supports OnLoad only. It can enable the instructions handler, but it does not enable the OnSave validator. [Microsoft Learn: Events in forms and grids](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/events-forms-grids).

## Question 10

Type: single\_choice
Knowledge point: Create client scripting that targets the Dataverse Web API

An online model-driven app command must set an existing task's Regarding lookup to an existing account with ID 6f3b2df8-98a4-4f4f-97a3-b841b34c7192\. The lookup column's logical name is `regardingobjectid`. Relevant excerpts from the environment's Web API metadata are:

```xml
<NavigationProperty Name="regardingobjectid_account_task" Type="mscrm.account">
  <ReferentialConstraint Property="_regardingobjectid_value" ReferencedProperty="accountid" />
</NavigationProperty>
<EntitySet Name="accounts" EntityType="mscrm.account" />
```

The command calls `Xrm.WebApi.online.updateRecord("task", taskId, data)`. Which assignment should it include in `data`?

### Options

**A**

Set `regardingobjectid@odata.bind` to `/accounts(6f3b2df8-98a4-4f4f-97a3-b841b34c7192)`.

**B**

Set `regardingobjectid_account_task@odata.bind` to `/account(6f3b2df8-98a4-4f4f-97a3-b841b34c7192)`.

**C**

Set `regardingobjectid_account_task@odata.bind` to `/accounts(6f3b2df8-98a4-4f4f-97a3-b841b34c7192)`.

**D**

Set `_regardingobjectid_value@odata.bind` to `/accounts(6f3b2df8-98a4-4f4f-97a3-b841b34c7192)`.

Correct answer: C

### Explanation

Associating the task with an existing account requires `@odata.bind` on the single-valued navigation property. The metadata supplies `regardingobjectid_account_task` as that property's name and `accounts` as the target entity set. Combine those names with the supplied account GUID. Using the lookup column's logical name is a tempting shortcut, but that name differs from the navigation property in this environment. Microsoft documents both the metadata-name requirement and lookup updates using navigation properties. [createRecord reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/createrecord), [updateRecord reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/updaterecord).

## Question 11

Type: single\_choice
Knowledge point: Create client scripting that targets the Dataverse Web API

An online model-driven app script makes this call:

```javascript
Xrm.WebApi.online.retrieveMultipleRecords("account", "?$select=name", 100);
```

The response contains 100 entities and a nonempty `nextLink`. Inspection of its `$skiptoken` shows sequences such as `%3Ccookie` and `%253C`. The script must retrieve the next page of the same result set. Which request should it make?

### Options

**A**

Extract the query portion of `nextLink`, starting with `?`, and pass it unchanged as `options` to `retrieveMultipleRecords` for `account`, with `maxPageSize` 100.

**B**

Extract the query portion of `nextLink`, apply `encodeURIComponent` to it, and pass that result as `options` to `retrieveMultipleRecords` for `account`, with `maxPageSize` 100.

**C**

Extract the query portion of `nextLink`, apply `decodeURIComponent` to it, and pass that result as `options` to `retrieveMultipleRecords` for `account`, with `maxPageSize` 100.

**D**

Pass the complete `nextLink` URL unchanged as `options` to `retrieveMultipleRecords` for `account`, with `maxPageSize` 100.

Correct answer: A

### Explanation

The returned continuation identifies the next page. For `retrieveMultipleRecords`, use its query portion unchanged and retain the original page size of 100\. The continuation is already URI encoded; encoding it again alters the paging-cookie information and can cause an error. The rule for encoding a newly constructed OData query does not authorize re-encoding a returned continuation. [Microsoft retrieveMultipleRecords reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrievemultiplerecords).

## Question 12

Type: single\_choice
Knowledge point: Create client scripting that targets the Dataverse Web API

A model-driven app runs in an offline-first mobile client. A command needs a `new_inspection` record whose GUID is known. The table is excluded from the user's offline profile and is unavailable in the local data store. The record exists on the server, read access has been verified, and the device currently has a working connection to Dataverse. Which approach should the command use without changing the offline profile?

### Options

**A**

Call `Xrm.WebApi.offline.retrieveRecord` for `new_inspection` and the known GUID now.

**B**

Wait for the next offline synchronization, then call `Xrm.WebApi.offline.retrieveRecord` for `new_inspection` and the known GUID.

**C**

Block retrieval until `new_inspection` is added to the offline profile, even while the device is connected.

**D**

Call `Xrm.WebApi.online.retrieveRecord` for `new_inspection` and the known GUID now.

Correct answer: D

### Explanation

The record is available on the server but unavailable locally, and connectivity is present. In an offline-first client, the explicit online API can access tables and records outside the offline profile when the client has network connectivity. The offline profile's exclusion therefore prevents the local route, not this server route. Waiting for ordinary synchronization does not address the table's exclusion from the profile. [Microsoft Xrm.WebApi reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi).

## Question 13

Type: single\_choice
Knowledge point: Create client scripting that targets the Dataverse Web API

A developer is implementing an online model-driven app command that invokes a custom Dataverse operation through `Xrm.WebApi.online.execute`. The environment's Web API metadata contains:

```xml
<Action Name="new_ReviewAccount" IsBound="true">
  <Parameter Name="entity" Type="mscrm.account" />
</Action>
```

The request object already supplies `entity` with the selected account reference. Which settings should its constructor prototype's `getMetadata` method return?

### Options

**A**

Use `operationName: "new_ReviewAccount"`, `boundParameter: "entity"`, and `operationType: 0`; describe the `entity` parameter with `typeName: "mscrm.account"` and `structuralProperty: 5`.

**B**

Use `operationName: "new_ReviewAccount"`, `boundParameter: null`, and `operationType: 0`; describe the `entity` parameter with `typeName: "mscrm.account"` and `structuralProperty: 5`.

**C**

Use `operationName: "new_ReviewAccount"`, `boundParameter: "entity"`, and `operationType: 1`; describe the `entity` parameter with `typeName: "mscrm.account"` and `structuralProperty: 5`.

**D**

Use `operationName: "new_ReviewAccount"`, `boundParameter: "entity"`, and `operationType: 0`; describe the `entity` parameter with `typeName: "mscrm.account"` and `structuralProperty: 1`.

Correct answer: A

### Explanation

The supplied definition is an action bound through the `entity` parameter to an account. Its request metadata must therefore name `entity` as the bound parameter, use action operation type 0, and classify `mscrm.account` as an entity type with structural property 5\. Including an account reference does not make `boundParameter: null` appropriate: that setting declares an unbound operation, contrary to this definition. [Microsoft execute reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/online/execute).

## Question 14

Type: single\_choice
Knowledge point: Create client scripting that targets the Dataverse Web API

An online model-driven app command invokes a custom Dataverse action that defines no return parameters. Its response handler is:

```javascript
const response = await Xrm.WebApi.online.execute(request);
if (!response.ok) {
  throw new Error("Request failed");
}
const result = await response.json();
showCompleted();
```

A trace shows `response.ok = true`, HTTP status `204`, and a response body of zero bytes. The call to `response.json()` rejects with a JSON parsing error, so the command never reaches `showCompleted()`. Which revision should the developer make?

### Options

**A**

Keep parsing every successful response as JSON and retry the action whenever `response.json()` rejects.

**B**

Read every successful response with `response.text()` and pass the returned text to `JSON.parse` before marking the action completed.

**C**

Require HTTP status 200 before marking the action completed and report status 204 as an action failure.

**D**

Handle the successful 204 response without JSON parsing and mark the action completed; parse other successful responses when their operation returns a JSON body.

Correct answer: D

### Explanation

The trace shows that the operation returned a successful response with no body, consistent with its lack of return parameters. The failure occurs afterward when the client tries to parse empty content as JSON. Complete the no-content path without deserialization, while retaining JSON parsing for operations that return a JSON body. Retrying the action treats a client parsing failure as evidence of server failure, which this trace does not support. Microsoft's execute examples explicitly omit JSON parsing when an operation returns no response content. [Microsoft execute reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/online/execute).

## Question 15

Type: single\_choice
Knowledge point: Create client scripting that targets the Dataverse Web API

An online model-driven app command has four prepared requests with valid request metadata:

* `Update1` and `Update2` update two existing rows. If either update fails, neither update may remain committed.
* `Read1` and `Read2` retrieve unrelated reference rows. Their results are not inputs to the updates, and no shared transactional snapshot is required.

The developer will submit all four requests in one `Xrm.WebApi.online.executeMultiple` call. How should the requests be grouped?

### Options

**A**

Put `Update1`, `Update2`, `Read1`, and `Read2` together in one change set within the batch.

**B**

Put `Update1` and `Update2` together in one change set, and include `Read1` and `Read2` as individual requests in the same batch.

**C**

Include `Update1`, `Update2`, `Read1`, and `Read2` as four individual requests in the batch.

**D**

Put each update in its own change set, and include `Read1` and `Read2` as individual requests in the same batch.

Correct answer: B

### Explanation

The two writes must share one transaction, so they belong in the same change set. The reads are independent and must remain individual requests because executeMultiple change sets cannot contain read operations. The method supports mixing a change set with individual requests in one batch. A flat batch sends multiple requests but does not give the updates the required shared transaction; separate change sets also fail to unite them. [Microsoft executeMultiple reference](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/online/executemultiple).

## Question 16

Type: single\_choice
Knowledge point: Configure commands and buttons by using Power Fx and JavaScript

A developer is adding two modern commands to an account main form in a browser-hosted model-driven app using Unified Interface: • Review requests confirmation, then sets the current saved account's Review Required Yes/No column to No. Accounts is already a data source in the command component library. • Details opens the same account's main form in a modal dialog that is 70% wide and 80% high. The team's coding standard prefers Power Fx when both Power Fx and JavaScript can meet a command's requirements. Which action assignment meets the behavior requirements and the coding standard?

### Options

**A**

Use Run formula for both Review and Details.

**B**

Use Run JavaScript for Review and Run formula for Details.

**C**

Use Run formula for Review and Run JavaScript for Details.

**D**

Use Run JavaScript for both Review and Details.

Correct answer: C

### Explanation

The confirmation and Dataverse update can use command Power Fx functions such as Confirm and Patch, so the team's preference selects Run formula for Review. The command navigation guidance directs additional navigation options to JavaScript. Details can use Xrm.Navigation.navigateTo with the existing account's entityId, target 2, and the required dialog dimensions in Unified Interface. JavaScript could implement both commands, but that would disregard the preference for Power Fx where it meets the requirements. See [Power Fx with commands](https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/commanding-use-powerfx) and [navigateTo](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto).

## Question 17

Type: single\_choice
Knowledge point: Configure commands and buttons by using Power Fx and JavaScript

A modern Power Fx command on the Accounts main grid in a browser-hosted model-driven app has SelectionMax set to 5\. When the command runs, exactly one account row is selected. What do Self.Selected.Item and Self.Selected.AllItems contain?

### Options

**A**

Self.Selected.Item contains the selected account record; Self.Selected.AllItems contains a one-row table.

**B**

Self.Selected.Item is Blank; Self.Selected.AllItems contains a one-row table.

**C**

Self.Selected.Item contains the selected account record; Self.Selected.AllItems contains an empty table.

**D**

Self.Selected.Item is Blank; Self.Selected.AllItems contains an empty table.

Correct answer: B

### Explanation

Self.Selected.Item is always Blank when SelectionMax is not 1, even if the user currently selects exactly one row. Self.Selected.AllItems contains all currently selected records, so it contains a one-row table here. The configured selection maximum determines Item's availability; the actual selection determines the contents of AllItems. See [the command Selected property](https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/commanding-use-powerfx#selected-property).

## Question 18

Type: single\_choice
Knowledge point: Configure commands and buttons by using Power Fx and JavaScript

A developer copies a form-event handler pattern into a JavaScript action for a classic ribbon button on the account main form. The action passes this sole parameter: &lt;CrmParameter Value="PrimaryControl" /&gt; The name column is present on the form. The relevant function is: function readAccountName(context) { const formContext = context.getFormContext(); return formContext.getAttribute("name").getValue(); } Selecting the button produces TypeError: context.getFormContext is not a function. Which change correctly obtains the form context supplied to this ribbon action?

### Options

**A**

Keep PrimaryControl, enable Pass execution context as first parameter for the form's OnLoad handler, and retain context.getFormContext().

**B**

Replace PrimaryControl with SelectedControl and assign the received argument directly to formContext.

**C**

Replace PrimaryControl with CommandProperties and retain context.getFormContext().

**D**

Keep PrimaryControl and assign the received context argument directly to formContext.

Correct answer: D

### Explanation

For a classic form ribbon action, PrimaryControl supplies the form context directly. The handler should therefore assign the received argument to formContext. Calling getFormContext() is the form-event pattern for an executionContext, which is a different argument contract. Changing an OnLoad registration does not change the ribbon parameter, and the grid-context or command-properties parameters do not supply the required form context. See [ribbon action parameters](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/pass-data-page-parameter-ribbon-actions#form-and-grid-context-in-ribbon-actions) and [Client API form context](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/clientapi-form-context).

## Question 19

Type: single\_choice
Knowledge point: Configure commands and buttons by using Power Fx and JavaScript

A modern command on an account main form uses Run formula to create a task regarding the current account: Patch(Tasks, Defaults(Tasks), {Subject: "Review account", Regarding: Self.Selected.Item}) Accounts and Tasks are available in Dataverse, and a Tasks page already appears in the model-driven app. Self.Selected.Item resolves to the current saved account. The command component library's Data pane lists only Accounts. Patch and Defaults are recognized, but Tasks is reported as an unknown name. Which change addresses the missing table reference while retaining the Power Fx formula?

### Options

**A**

Open the app's existing command component library in Power Apps Studio and add Tasks as a data source.

**B**

Open the app's existing command component library in Power Apps Studio and refresh the Accounts data source.

**C**

Add the Tasks table to the solution containing the app and publish the solution customizations.

**D**

Save and republish the model-driven app from the app designer.

Correct answer: A

### Explanation

Tasks exists in the app, but the command component library has only Accounts as a data source. A Power Fx command that references the related Tasks table needs that table added to its command component library in Power Apps Studio. App navigation and solution membership do not establish the missing library data source. Refreshing Accounts updates that existing source's metadata rather than adding Tasks. See [adding command data sources](https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/use-command-designer#use-power-fx-for-actions-and-visibility), [creating a related record](https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/commanding-use-powerfx#patch-function), and [command library limitations](https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/command-designer-limitations#power-fx-and-command-component-libraries-limitations).

## Question 20

Type: single\_choice
Knowledge point: Implement navigation, dialogs, and notifications by using the Client API

A developer implements an account creation command in a model-driven app running Unified Interface. Users must complete the account main form in a dialog. After an account is saved and the dialog closes, the command must obtain the saved row reference. The account table allows quick create, and its main and quick-create forms are included in the app. Which approach meets these requirements?

### Options

**A**

Use openForm with useQuickCreateForm set to false, and read savedEntityReference in its success callback.

**B**

Use openForm with useQuickCreateForm set to true, and read savedEntityReference in its success callback.

**C**

Use navigateTo with an entityrecord page, omit entityId, set target to 2, and read savedEntityReference when its promise resolves.

**D**

Use navigateTo with an entityrecord page, omit entityId, set target to 1, and read savedEntityReference when its promise resolves.

Correct answer: C

### Explanation

The required experience is an account main form in a dialog, with the saved row reference obtained after the dialog closes. In Unified Interface, navigateTo with an entityrecord page, no entityId, and target 2 opens a create dialog; its resolved result supplies savedEntityReference for the created row. An openForm quick-create success callback can supply a saved reference, but that route displays a quick-create form rather than the required main form. See [navigateTo](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto) and [openForm](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openform).

## Question 21

Type: single\_choice
Knowledge point: Implement navigation, dialogs, and notifications by using the Client API

A developer adds a Place on hold command to a model-driven order form. The command uses Xrm.Navigation.openConfirmDialog with Place on hold as the confirm-button label and Keep status as the cancel-button label. The function setOrderOnHold updates the order's status. It must run only when the user selects Place on hold; selecting Keep status or closing the dialog with X must leave the status unchanged. How should the command invoke setOrderOnHold?

### Options

**A**

Call setOrderOnHold immediately after calling openConfirmDialog.

**B**

Call setOrderOnHold in the success callback only when result.confirmed is true.

**C**

Call setOrderOnHold in the success callback whenever the result object is truthy.

**D**

Call setOrderOnHold whenever the success callback executes.

Correct answer: B

### Explanation

The status update requires an affirmative user choice. openConfirmDialog invokes its success callback when the user confirms, cancels, or closes the dialog with X. The returned object's confirmed Boolean distinguishes these outcomes, so setOrderOnHold must run inside that callback only when confirmed is true. Successful dialog closure or a truthy result object does not establish consent. See [openConfirmDialog](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openconfirmdialog).

## Question 22

Type: single\_choice
Knowledge point: Implement navigation, dialogs, and notifications by using the Client API

A developer implements a tax-number check on a model-driven account form. An invalid value must display an error and block saving. The handler must remove the error after the user corrects the value. The tax number uses a standard text control in a visible section and tab, and no other validation blocks this save. Which notification plan should the developer use?

### Options

**A**

While invalid, use formContext.ui.setFormNotification with level ERROR; when valid, use formContext.ui.clearFormNotification with the same identifier.

**B**

While invalid, use the tax-number control's setNotification; when valid, use formContext.ui.clearFormNotification with the same identifier.

**C**

While invalid, use formContext.ui.setFormNotification with level ERROR; when valid, use the tax-number control's clearNotification with the same identifier.

**D**

While invalid, use the tax-number control's setNotification; when valid, use that control's clearNotification with the same identifier.

Correct answer: D

### Explanation

A control error created with setNotification blocks the form from saving. The tax-number control and its parent section and tab are visible, so users can reach and correct the error. Clearing that control notification after successful validation removes the blocking error. A form-level ERROR notification displays an error icon; choosing that display level does not provide the control's save-blocking behavior. The clearing method must match the notification's scope. See [setNotification](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/controls/setnotification) and [setFormNotification](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/formcontext-ui/setformnotification).

## Question 23

Type: single\_choice
Knowledge point: Implement navigation, dialogs, and notifications by using the Client API

A model-driven app calls Xrm.App.addGlobalNotification twice: once for Catalog refresh in progress and once for Review overdue. Both calls use type 2 and level 4\. The value received by the refresh call's success callback is stored in refreshResult. When the refresh finishes, the app must remove only its message. Which action should the developer take?

### Options

**A**

Pass refreshResult to Xrm.App.clearGlobalNotification.

**B**

Pass the text Catalog refresh in progress to Xrm.App.clearGlobalNotification.

**C**

Pass the type value 2 to Xrm.App.clearGlobalNotification.

**D**

Pass refreshResult to formContext.ui.clearFormNotification.

Correct answer: A

### Explanation

The success callback for addGlobalNotification receives the GUID that identifies the displayed app-bar notification. Therefore, refreshResult contains the value to pass to clearGlobalNotification when the refresh finishes. Message text and type describe the notification rather than identify its instance, and a form-notification clearing method operates at a different scope. See [addGlobalNotification](https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-app/addglobalnotification).

