Create Record in Dynamics 365 using jQuery

Leave a comment

To create a new record of an entity in Dynamics 365, use the code below:

var account = {};
account.Name = "Sample Account";
var jsonAccount = window.JSON.stringify(account);

if (typeof($) === 'undefined') {
 $ = parent.$;
 jQuery = parent.jQuery;
}

$.ajax({
 type: "POST",
 contentType: "application/json; charset=utf-8",
 datatype: "json",
 url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet",
 data: jsonAccount,
 beforeSend: function (XMLHttpRequest) {
 //Specifying this header ensures that the results will be returned as JSON.
 XMLHttpRequest.setRequestHeader("Accept", "application/json");
 },
 success: function (data, textStatus, XmlHttpRequest) {
 account = data.d;
 alert("Success");
 },
 error: function (XMLHttpRequest, textStatus, errorThrown) {
 errorHandler(XMLHttpRequest, textStatus, errorThrown);
 }
});

This will create the account in Dynamics 365:

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, BI, Web, Cloud and Data Science.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

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