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:
Hope you have successfully Deleted an Account record using New Syntax.