Web API for Create, Update, Delete record
1. Create Web API Request :
Syntax:
Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback);
//json object
var entity = {};
entity.address1_country = "India";
entity["areaid@odata.bind"] = "/areas(0b4ecbb5-e574-eb11-a812-0022481a9090)"; //lookup field
Xrm.WebApi.online.createRecord("account", entity).then(
function success(result) {
var newEntityId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
syntax :
Xrm.WebApi.updateRecord(entityLogicalName, id, data).then(successCallback, errorCallback);
//json object
var entity = {};
entity["areaid@odata.bind"] = "/areas(0b4ecbb5-e574-eb11-a812-0022481a9090)"; //lookup field
entity.address2_country = "India";
Xrm.WebApi.online.updateRecord("account", "0b4ebjb5-e574-eb11-a812-0022481a9090", entity).then(
function success(result) {
var updatedEntityId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
3. Delete Web API Request :
Syntax :
Xrm.WebApi.deleteRecord(entityLogicalName, id).then(successCallback, errorCallback);
Xrm.WebApi.online.deleteRecord("account", "0b4ecbb5-e574-eb11-a812-0022481a9090").then(
function success(result) {
//Success - No Return Data - Do Something
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
Comments
Post a Comment