locked
using oData and javascript to retrieve record form CRM 2011 DB RRS feed

  • Question

  • Hi all,

     

    I've tried to use the below code sample and the Jquery web resource on the onLoad event of account to retrieve record form CRM 2011 DB:

    function init()
    {
     // write required ODATA query
     var guid = Xrm.Page.data.entity.getId();
     var odataSelect = "http://server/organization/XRMServices/2011/OrganizationData.svc/AccountSet(guid'D55AE4C2-E144-E011-93C2-000C297ED18C')";
    
     $.ajax({
     type: "GET",
     contentType: "application/json; charset=utf-8",
     datatype: "json",
     url: odataSelect,
     beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
     success: function (data, textStatus, XmlHttpRequest)
     {
    
      RetrieveEntityData(data.d);
    
     },
     error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
     });
    }
    
    
    
    function RetrieveEntityData(Entity)
    {
     // get the fields from the Entity object
     var accountNumber = Entity.AccountNumber;
     var AccountName = Entity.Name;
    
     alert("Account Name "+Entity.Name);
    }
    

     but the problem is that this web resource use a static GUID so that whatever the loaded account it retrieve the name of a specific account, I need to update the above code to use a dynamic GUID using "Xrm.Page.data.entity.getId()"

     

    could anybody please help me on this ??

     

    Sunday, May 8, 2011 4:14 PM

Answers

  • var guid = Xrm.Page.data.entity.getId();
    var odataSelect = "http://server/organization/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + guid + "')";
    

    --pogo (pat)
    Sunday, May 8, 2011 7:06 PM

All replies

  • var guid = Xrm.Page.data.entity.getId();
    var odataSelect = "http://server/organization/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + guid + "')";
    

    --pogo (pat)
    Sunday, May 8, 2011 7:06 PM
  • Hi Mostafa,

    How can we set the value of lookup field.

    Regards

    Mrpathan

    Wednesday, December 19, 2012 11:02 AM