CRUD (Update) Operation on Dynamics 365

How to Update Records on Dynamics 365 CRUD in Dynamics 365

On this Section we will see the How to Update the records on Dynamics 365 instance.

There is a "updateRecord" method used to update records

1. To Update the records Xrm.WebApi.updateRecord the required parameter is given below:
- Entity Logical Name
- Entity Guid
- Entity Object



Syntax : Xrm.WebApi.updateRecord("Entiy", "Guid", "object")


Example : Update Record
//Note :- Initialized the XRM boject first
var Xrm = parent.Xrm;
//Step 1- Create a Javascript fumction
function updateContact() {
var ownerId = null;
var contactObj = null;
try {
// create the contact object
contactObj = new Object();

//set the properties
contactObj.creditonhold = true;
//set optionsetvalue
contactObj.accountrolecode = 3;
//set the lookup value
ownerId = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx";
contactObj["ownerid@odata.bind"] = "/systemusers(" + ownerId + ")"
// pass entity logical name , entity guid, entity object
Xrm.WebApi.updateRecord("contact","51A0E5B1-98AF-E456-B8D3-7C8BD588B120", contactObj).then(function (result) {
Xrm.Utility.alertDialog("Record updated.");
}).fail(function (error) {
Xrm.Utility.alertDialog(error.message);
});

} catch (e) {
Xrm.Utility.alertDialog(e.message);
}
}

Comments