Hi there,
I have used rest end point to createa record from ribbon button click on a system form. It is working fine...but some times it doesn't work and again later it starts working. So there is a chance of creating unnecessary records but mistake.
sample code
function createRecord(concatenatedorders) {
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var CRMObject = new Object();
/////////////////////////////////////////////////////////////
// Specify the ODATA entity collection
var ODATA_EntityCollection = "/skyscale_invoiceprocessingSet";
// alert("Entered the Odata entity point");
/////////////////////////////////////////////////////////////
// Define attribute values for the CRM object you want created
CRMObject.skyscale_invoicegroup = concatenatedorders;
CRMObject.skyscale_invoicebatch = { Id: invoiceBatchId, LogicalName: 'skyscale_invoicebatch' };
CRMObject.skyscale_requesttype = { Value: requesttype };
// CRMObject.Telephone1 = "123";
// CRMObject.Fax = "456";
//Parse the entity object into JSON
var jsonEntity = window.JSON.stringify(CRMObject);
// var jsonEntity = CRMObject;
//Asynchronous AJAX function to Create a CRM record using OData
$.ajax({ type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,
data: jsonEntity,
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) {
alert("success");
var NewCRMRecordCreated = data["d"];
// alert("CRM GUID created: " + NewCRMRecordCreated.skyscale_invoiceprocesssingId);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("failure");
}
});
}
Here I am bit confussed am I missing something or using rest end point is not that good advice
FYI
Environment : CRM 2011 on premise multitenant
onload of the form: Jquery, json libraries
when the functionality doesnt work, I do IIS reset, aynchronous reset but still doesn't work
Kind Regards,
SAMA