Create, Update, Delete data Client side using XRM Web API in Dynamics 365 (Client API Reference)

Introduction

Below is the Syntax that’s available to create, delete, update a record in Dynamics 365 Online V9.X using JavaScript.

Create record (Client API Reference)

Below is the Syntax that’s available to create a record in Dynamics 365 Online V9.X using JavaScript

Syntax :

Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback);

Implementation :

Let’s take an example where you would like to Create the Account record.

// define the data to create new account
var data =
{
"name": "Sample Account",
"creditonhold": false,
"address1_latitude": 47.639583,
"description": "This is the description of the sample account",
"revenue": 5000000,
"accountcategorycode": 1
}

// 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
}
);

Update record (Client API Reference)

Below is the Syntax that’s available to update a record in Dynamics 365 Online V9.X using JavaScript

Syntax 

Xrm.WebApi.updateRecord(entityLogicalName, id, data).then(successCallback, errorCallback);

Implementation :

Let’s take an example where you would like to Update the Account record.

// define the data to update account
var data = {
"name": "Updated Sample Account ",
"creditonhold": true,
"address1_latitude": 47.639583,
"description": "This is the updated description of the sample account",
"revenue": 6000000,
"accountcategorycode": 2
}
// update the record
Xrm.WebApi.updateRecord("account", "5531d753-95af-e711-a94e-000d3a11e605", data).then(
function success(result) {
console.log("Account updated");
// perform operations on record update
},
function(error) {
console.log(error.message);
// handle error conditions
}
);

Delete record (Client API Reference)

Below is the Syntax that’s available to delete a record in Dynamics 365 Online V9.X using JavaScript

Syntax :

Xrm.WebApi.deleteRecord(entityLogicalName, id).then(successCallback, errorCallback);

Implementation :

Let’s take an example where you would like to Delete the Account record.

Xrm.WebApi.deleteRecord("account", "5531d753-95af-e711-a94e-000d3a11e605").then(
function success(result) {
console.log("Account deleted");
// perform operations on record deletion
},
function (error) {
console.log(error.message);
// handle error conditions
}
);

Hope this Helps ….


Share Story :