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

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

Syntax:

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

Parameters:

Name Type Required Description
entityLogicalName String Yes The entity logical name of the record you want to update. For example: “account”.
id String Yes GUID of the entity record you want to update.
data Object Yes A JSON object containing key: value pairs, where key is the property of the entity and value is the value of the property you want to update.

See examples later in this topic to see how you can define the data object for various update scenarios.

successCallback Function No A function to call when a record is updated. An object with the following properties will be passed to identify the updated record:

·        entityType: String. The entity type of the updated record.

·        id: String. GUID of the updated record.

errorCallback Function No A function to call when the operation fails. An object with the following properties will be passed:

·        errorCode: Number. The error code.

·        message: String. An error message describing the issue.

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 UpdateAccountRecord() {
 // define the data to update a record
 var data =
 {
 "name": "Arun Potti Inc", // Single Line of Text
 "creditonhold": true, // Two Option Set
 "description": "This is the description of the sample account after update", // Multiple Lines of Text
 "revenue": 20000000, // Currency
 "industrycode": 2, // 2 - Agriculture and Non-petrol Natural Resource Extraction // OptionSet
 "primarycontactid@odata.bind": "/contacts(39582A13-E6E7-E711-A95E-000D3AF27CC8)" // ContactId - Arun Potti // Lookup
 }
 // Update the Account Record
 Xrm.WebApi.updateRecord("account", "9CCDEB5F-E9E7-E711-A95E-000D3AF27CC8", data).then(
 function success(result) {
 // Perform operations on record update
 Xrm.Utility.alertDialog("Account updated successfully", null);
 },
 function (error) {
 // Handle error conditions
 Xrm.Utility.alertDialog(error.message, null);
 }
 );
}

Output:
Dynamics 365 Update Record V9.X

Hope you have successfully updated a record using New Syntax.

Advertisements

2 thoughts on “How to update a record in Dynamics 365 Online V 9.X using JavaScript WebAPI?

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.