Extending Model-Driven App with JavaScript Client Script

Retrieve Multiple Records from Dataverse Contact Table using Web API

Question

You need to extend the model-driven app by using a JavaScript client script.

The script should retrieve multiple records from the Dataverse contact table using Web API.

What Client API object would you use for data retrieval?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

Correct Answer: D

Power Apps provides the Client API model for model-driven apps for users to implement in their business logic.

The Client API model includes objects and methods that developers can access using Javascript code.

There are four root objects of the Client API model: executionContext - this is an execution object of the model-driven app.

It gives access to the context of the forms and grids.

formContext - provides access to the form object using the executionContext.

gridContext - provides access to the grid (subgrid) on a form.

Xrm - provides access to the global object for operations that do not directly impact UI and data in forms, grids, controls.

The Xrm.WebAPI object uses Web API for the Dataverse data access.

It has two properties: online and offline.A list of methods includes the record operations, a retrieval of the multiple records, and execution of the single or multiple actions, functions, or CRUD operations.

To retrieve multiple records from the Dataverse contact table, you use the retrieveMultipleRecords method, like in the following statement:

parent.Xrm.WebApi. retrieveMultipleRecords("contact",'"?$select=fullname, emailaddressi&$top=3").then(
function success(result) {
for (var i = 0; i < result.entities. length; i++) {
alert(result.entities [i].fullname) ;
// perform additional operations on retrieved records

All other options are incorrect.

For more information about model-driven app's Client API scripts using WebAPI, please visit the below URLs:

The Client API object that can be used for data retrieval from the Dataverse contact table using Web API is D. Xrm.WebAPI.

Explanation:

Model-driven apps in Power Platform are built using the Common Data Service (CDS), which stores data in Dataverse. Client-side scripts are often used to extend the functionality of these apps.

To retrieve multiple records from the Dataverse contact table using Web API, the Xrm.WebAPI client-side object can be used. This object provides methods for CRUD (create, read, update, delete) operations and other common operations like querying and executing actions. The Web API is a RESTful API that provides a programming interface to access the data and metadata in Dataverse.

The Xrm.WebAPI object provides a method called retrieveMultipleRecords(entityLogicalName, options, maxPageSize) that can be used to retrieve multiple records from the specified entity. The entityLogicalName parameter specifies the name of the entity to retrieve records from, in this case, the contact entity. The options parameter is an object that can be used to specify filters, sorting, and other options for the query. The maxPageSize parameter specifies the maximum number of records to retrieve per page.

Example usage of the Xrm.WebAPI object for retrieving multiple contact records using Web API:

javascript
var entityLogicalName = "contact"; var options = "?$select=fullname,emailaddress1&$filter=statecode eq 0"; var maxPageSize = 50; Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then( function success(result) { console.log("Retrieved " + result.entities.length + " contacts"); for (var i = 0; i < result.entities.length; i++) { console.log(result.entities[i].fullname + " - " + result.entities[i].emailaddress1); } }, function(error) { console.log(error.message); } );

In this example, the retrieveMultipleRecords method is called with the entityLogicalName parameter set to "contact", options parameter set to select the fullname and emailaddress1 fields and filter the results to only include active contacts (statecode eq 0), and maxPageSize parameter set to 50. The success callback function logs the number of retrieved contacts and loops through the entities array to log the full name and email address of each contact. The error callback function logs any errors that occur during the retrieval process.

Therefore, the correct answer to the question is D. Xrm.WebAPI.