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:


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
