To create a record in Dynamics with Xrm.WebApi the syntax below can be used. In the example below we create an account record with multiple fields about the account and a reference to a primary contact of the account.
let data = {
"name": "Litware Publishing",
"description": "An example account created with Xrm WebApi.",
"telephone1": "+09-70-01-90-90",
"address1_line1": "39, quai du Roosevelt",
"address1_city": "Paris",
"address1_postalcode": "address1_postalcode",
"address1_country": "France",
"primarycontactid@odata.bind": "/contacts(53a0e5b9-88df-e311-b8e5-6c3be5a8b200)",
}
// Create account record
await Xrm.WebApi.createRecord("account", data).then(
function success(result) {
console.log("Account created with ID: " + result.id);
},
function (error) {
console.log(error.message);
}
);
In the image below it show how it looks when running the script in the developer console in the browser.