Showing posts with label JSON in crm 2011. Show all posts
Showing posts with label JSON in crm 2011. Show all posts

Friday, December 28, 2012

Read records synchronously using JSON in CRM 2011


function retrieveRecordsSynchronously() {
     var retrieveRecordsReq = new XMLHttpRequest();
     var ODataPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet";
     retrieveRecordsReq.open('GET', ODataPath, false);
     retrieveRecordsReq.setRequestHeader("Accept", "application/json");
     retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
     retrieveRecordsReq.send(null);
     var records = JSON.parse(retrieveRecordsReq.responseText).d;
     //Read the first account name
     alert('First Account Name is: ' + records.results[0].Name);
 }