Home › Dynamics 365 Customer Engagement (CRM) › Creating a Record using Xrm.WebApi in Dynamics 365 JavaScript
Dynamics 365 Customer Engagement (CRM) · Aug 7, 2018 · 1 MIN READ

Creating a Record using Xrm.WebApi in Dynamics 365 JavaScript

To create a record using Xrm.WebApi, use the following syntax. We will use the example where we are creating an account record with 3 fields:

[sourcecode language=”JavaScript”] var entity = {};
entity.name = "Test Account";
var parentAccountId = "e46bf6d0-86b6-ea11-a812-000d3a300fca";
entity["parentaccountid@odata.bind"] = "/accounts(" + parentAccountId + ")";
entity.industrycode = 4;
entity.websiteurl = "carldesouza.com";

Xrm.WebApi.online.createRecord("account", entity).then(
function success(result) {
var recordId = result.id;
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
[/sourcecode]

The record is then created:

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.