How to delete a record in Dynamics 365 Online V 9.X using JavaScript WebAPI?

Below is the latest Syntax available to delete a record in Dynamics 365 Online V9.X using JavaScript,

Syntax:

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

Parameters:

Name Type Required Description
entityLogicalName String Yes The entity logical name of the record you want to delete. For example: “account”.
id String Yes GUID of the entity record you want to delete.
successCallback Function No A function to call when a record is deleted. An object with the following properties will be passed to identify the deleted record:

·        entityType: String. The entity type of the record.·        id: String. GUID of the record.

·        name: String. Name of the record.

errorCallback Function No A function to call when the operation fails.

Return Value:
On success, returns a promise object containing the attributes specified earlier in the description of the successCallback parameter.

Example:
Create a new Javascript Webresource (new_Account.js) and copy paste the below code in it and call it on OnLoad of the Account Form.

After that, open an existing Account record.

function DeleteRecord() {
 // Delete Account record
 Xrm.WebApi.deleteRecord("account", "9C36DC38-79E9-E711-A95E-000D3AF27CC8").then(
 function success(result) {
 // Perform operations on record deletion
 Xrm.Utility.alertDialog("Account deleted", null);
 },
 function (error) {
 // Handle error conditions
 Xrm.Utility.alertDialog(error.message, null);
 });
}

Output:

Dynamics 365 Record Deletion V9.X

Hope you have successfully Deleted an Account record using New Syntax.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.