Thursday, 23 May 2013

O data Query in Java Script mscrm 2011

 
 
The Open Data Protocol (OData) enables the creation of REST-based data services, which allow resources, identified using Uniform Resource Identifiers (URIs) and defined in a data model, to be published and edited by Web clients using simple HTTP messages. This specification defines a set of recommended (but not required) rules for constructing URIs to identify the data and metadata exposed by an OData server as well as a set of reserved URI query string operators, which if accepted by an OData server, MUST be implemented as required by this document.
The [OData:Atom] and [OData:JSON] documents specify the format of the resource representations that are exchanged using OData and the [OData:Operations] document describes the actions that can be performed on the URIs (optionally constructed following the conventions defined in this document) embedded in those representations.
It is encouraged that servers follow the URI construction conventions defined in this specification when possible as such consistency promotes an ecosystem of reusable client components and libraries.
The terms used in this document are defined in the [OData:Terms] document.
 
function RetrieveAccountInfo()
{
    var account = Xrm.Page.getAttribute("accountid").getValue();
    var accountid = account[0].id.toString();
    
    var request = new XMLHttpRequest();
    var EntitySet = "accountSet";

    var query = "$filter=accountid/Id eq guid'" + accountid + "'";

    request.open("GET", ODataPath + "/" + EntitySet + "?" + query, false);
    request.setRequestHeader("Accept", "application/json");
    request.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    request.send();

    if (request.status == 200) {
        var retrievedData = JSON.parse(request.responseText).d;
        if (retrievedData && retrievedData.results) {
            var current = retrievedData.results[0];
            var accountnumber = current.accountnumber;
            var accountname = current.name;

        }
   }
}

No comments:

Post a Comment