Hi,
If you are using WebApi, the following should be your code to create a Contact record:
var entity = {};
entity.firstname = "John";
entity.lastname = "Smith";
entity.emailaddress1 = "john.smith@contoso.com";
entity.new_createdfromwebapi = 1;
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
The newEntityId will return the newly created contact Id value from your request. If there is a value there, you know contact is created.
You can add a field to your contact entity called Created from Api, which you pass to your contact form that will specify when this was created from the Web Api. You can probably use one of the existing fields on the contact entity for this as well.
Hope this helps.