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

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


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


Name Type Required Description
entityLogicalName String Yes Logical name of the entity you want to create. For example: “account”.
data Object Yes A JSON object defining the attributes and values for the new entity record.

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

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

·        entityType: String. The entity logical name of the new record.

·        id: String. GUID of the new 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.

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

After that, open any existing Account record

function CreateAccountRecord() {
 // Define the data to create new account
 var accountData =
 "name": "Arun Potti Inc.", // Single Line of Text
 "creditonhold": false, // Two Option Set
 "description": "This is the description of the sample account", // Multiple Lines of Text
 "revenue": 10000000, // Currency
 "industrycode": 1, // 1 - Accounting // OptionSet
 "primarycontactid@odata.bind": "/contacts(39582A13-E6E7-E711-A95E-000D3AF27CC8)" // ContactId - Arun Potti // Lookup

// Create account record
 Xrm.WebApi.createRecord("account", accountData).then(
 function success(result) {
 // Show Account GUID
 Xrm.Utility.alertDialog("Account created with ID: " +, null);
 function (error) {
 // Show Error
 Xrm.Utility.alertDialog("Error :" + error.message, null);


Dynamics 365 Record Creation V9.X

Hope you have successfully created a record using New Syntax.


Leave a Reply

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

You are commenting using your 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.