Powered by Blogger.

Record Create with Odata and JQuery | MSCRM point

Record Create with Odata and JQuery 


future reference stuff :)

 functionRecordCreate()   
 {  
 if(Xrm.Page.getAttribute('new_name') != null)    
 {  
 var name = Xrm.Page.getAttribute('new_name').getValue();  
 }  
 var context = Xrm.Page.context;  
 varserverUrl = context.getServerUrl();  
 var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";  
 varCRMObject = new Object();  
 varODATA_EntityCollection = "/AccountSet";        
 CRMObject.Name = name;              
 varjsonEntity = window.JSON.stringify(CRMObject);  
   $.ajax({ type: "POST",  
 contentType: "application/json; charset=utf-8",  
 datatype: "json",  
 url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,  
 data: jsonEntity,  
 beforeSend: function (XMLHttpRequest) {  
 XMLHttpRequest.setRequestHeader("Accept", "application/json");  
     },  
 success: function (data, textStatus, XmlHttpRequest) {  
 alert("success");  
 varNewCRMRecordCreated = data["d"];  
 alert("CRM GUID created: " + NewCRMRecordCreated.AccountId);    
     },  
 error: function (XMLHttpRequest, textStatus, errorThrown) {  
 alert("failure");  
     }  
   });  
 }