Retrieve The Values Using ODATA Restend Point Javascript in MS CRM 2011

function Onload() {

    var RecId = Xrm.Page.data.entity.getId();

    var userId = Xrm.Page.context.getUserId();

    var fieldname = Xrm.Page.getAttribute(<fieldname>);

    if (fieldname != null && !fieldname.getValue()) {

        var fwdFilter = “EntitySet?$select= <Retrieved field names>&$orderby=ModifiedOn desc&$filter=<Field Name>/Id eq guid'” + RecId + “‘ and <Field Name> eq false and

<Field Name>/Id eq guid'” + userId + “‘”;

        var fwdResult = ODataRetrieveMultiple(fwdFilter);

        if (fwdResult != null) {

            alert(“Not Yet Fieldnamenowledged this Request”);

            Xrm.Page.ui.close();

        }

    }

function ODataRetrieveMultiple(filter) {

    var serverUrl = Xrm.Page.context.getServerUrl();

    var oDataEndpointUrl = serverUrl + “/XRMServices/2011/OrganizationData.svc/”;

    oDataEndpointUrl += filter;

    var service = GetRequestObject();

    if (service != null) {

        service.open(“GET”, oDataEndpointUrl, false);

        service.setRequestHeader(“X-Requested-Width”, “XMLHttpRequest”);

        service.setRequestHeader(“Accept”, “application/json, text/javascript, */*”);

        service.send(null);

        var requestResults = eval(‘(‘ + service.responseText + ‘)’).d;

        if (requestResults != null && requestResults.results.length > 0) {

            return requestResults.results;

        }

    }

    returnnull;

}

 

function GetRequestObject() {

    if (window.XMLHttpRequest) {

        returnnew window.XMLHttpRequest;

    }

    else {

        try {

            returnnew ActiveXObject(“MSXML2.XMLHTTP.3.0”);

        }

        catch (ex) {

            returnnull;

        }

    }

}

Hope it will help you.

Cheers,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s