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);
 }

1 comment:

  1. Very useful site for all the students and must be shareable site. thanks a lot for the post!!
    Microsoft Dynamics AX Training | Microsoft Dynamics CRM Online Training

    ReplyDelete