PL 400 : Create client-side scripts that target the Dataverse Web API (Apply business logic using client scripting)
Dataverse empowers organizations to work with any type of data and any type of app, and use the data within it to gain insights and drive business action. As part of Microsoft Power Platform, Dataverse requires no or little code to be written, so it can easily be used by everyone from knowledge workers to professional developers. Knowing that it's built on Azure, organizations choosing Dataverse can be confident that it's globally available, compliant, scalable, and secure.
Microsoft Dataverse “Common data service” is a cloud-based storage space that organizations can use to store business application data.
Dataverse Web API is one of two web services that we can use to work with data, and table and column definitions in Dataverse. It provides a development experience that can be used across a wide variety of programming languages, platforms, and devices. Because Dataverse Web API is designed to be an open standard. We can write HTTP requests for specific operations or use third party libraries to generate classes for any language or platform.
Dataverse Web API provides a RESTful style for interacting with data. This feature is an OData v4 RESTful endpoint that provides named operations via functions or actions. We interact with the Web API by making and sending HTTP requests. Dataverse provides a number of predefined operations that you can trigger via Web API requests. If we want to retrieve data for an entity set, use a GET request. When retrieving data, we can apply query options to set criteria for the entity (table) data we want and the entity properties (columns) to be returned. Use POST request to send data to create table row (entity record). We can create multiple related table rows in a single operation using Deep Insert. We also need to know how to set the value to associate a new table row with existing tables using the @odata.bind annotation.
Example :
Create records : To create records, use the HTTP POST method.
POST [Organization URI]/api/data/v9.0/accounts HTTP/1.1
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
{
"name": "Microsoft",
"creditonhold": true,
"description": "This is the description of the Microsoft Account",
"revenue": 100000000,
"accountcategorycode": 1
}
Retrieve records: To retrieve records, use the HTTP GET method.
GET [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001)
Xrm.WebApi:
The Xrm.WebApi object provides properties and methods for using the Web API for traditional CRUD operations within client scripts. When using Xrm.WebAPI, authentication is handled automatically in the context of the current user using the app.
JavaScript Code :
// define data to create primary and related table records
var data =
{
"name": "Microsoft",
"primarycontactid":
{
"firstname": "Elan",
"lastname": "Donald"
}
}
// create account record
Xrm.WebApi.createRecord("account", data).then(
function success(result) {
console.log("Account created with ID: " + result.id);
// perform operations on record creation
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
Comments
Post a Comment