web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

oData query

(0) ShareShare
ReportReport
Posted on by 180

Hi, I try to do the same thing as shown in this link with my custom entities:

http://rajeevpentyala.wordpress.com/2012/03/26/retrieve-multiple-records-using-odata-jquery-in-crm-2011/ , but get an error:

 

here is my code:

function retrieveMultiple(odataSetName, select, filter, successCallback) {

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

var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "?";

if (select) {

odataUri += "$select=" + select + "&";

}

if (filter) {

odataUri += "$filter=" + filter;

}

//Asynchronous AJAX function to Retrieve CRM records using OData

$.ajax({

type: "GET",

contentType: "application/json; charset=utf-8",

datatype: "json",

url: odataUri,

beforeSend: function (XMLHttpRequest) {

//Specifying this header ensures that the results will be returned as JSON.

XMLHttpRequest.setRequestHeader("Accept", "application/json");

},

success: function (data, textStatus, XmlHttpRequest) {

if (successCallback) {

if (data && data.d && data.d.results) {

successCallback(data.d.results, textStatus, XmlHttpRequest);

}

else if (data && data.d) {

successCallback(data.d, textStatus, XmlHttpRequest);}

else {

successCallback(data, textStatus, XmlHttpRequest);}

}},

error: function (XmlHttpRequest, textStatus, errorThrown) {

if (XmlHttpRequest && XmlHttpRequest.responseText) {

alert("Error while retrieval ; Error - " + XmlHttpRequest.responseText);

}}});

}

//-------------------------------------------------------------------------------------

function readRecordsOnSuccess(data, textStatus, XmlHttpRequest) {

// Loop through the retrieved records

for (var indx = 0; indx < data.length; indx++) {

alert("Name - " + data[indx].new_debet+" "+data[index].new_credit);

}

}

//-----------------------------------------------------------------

function retrieveContactsByAccountId() {

// Pass 'Contact' set name since we are reading Contacts

var oDataSetName = "new_banking_turnover_month_yearSet";

// Column names of 'Contact' (Pass * to read all columns)

var columns = "new_debet,new_credit";

// Read Account Guid

var accountId = Xrm.Page.data.entity.getId()

// Prepare filter

var filter = "new_banking_turnoverId/Id eq guid'" + accountId + "'";

retrieveMultiple(oDataSetName, columns, filter, readRecordsOnSuccess);

}

 

Thanks! 

*This post is locked for comments

I have the same question (0)
  • Abhishek D Divekar Profile Picture
    on at

    I think your code is correct, but while retrieving data just check that records are available are not. If records are available then those are not store in your oData end point.

  • Verified answer
    Mary GH Profile Picture
    2,215 on at

    hi, here is my version:

     

    function Account_onchange() {

      

     

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

        if (accountId != null) {

            alert(accountId);

           var contacts = GetContactsByAccount(accountId);

           

                if (contacts != null && contacts[0].results.length > 0) {

                    for (var count = 0; count < contacts[0].results.length; count++) {

     

                        var amount1 = contacts[0].results[count].yourfield1;

                        var amount2 = contacts[0].results[count].yourfield2;

     

     

                        alert (parseFloat(eval(amount2.Value)));// for money fields

     

                         alert (parseFloat(eval(amount1.Value))); // for money fields

     

                    }

       }

            }

        }

     

     

    function GetContactsByAccount(accountId) {

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

        var oDataUri = serverUrl + "/xrmservices/2011/OrganizationData.svc/'Your custom entity name'Set?$select=yourfield1,yourfield2&$filter=custom entity's ID/Id eq guid'" + accountId + "'";

        var jSonArray = new Array();

     

        jQuery.ajax({

            type: "GET",

            contentType: "application/json; charset=utf-8",

            datatype: "json",

            url: oDataUri,

            async: false,

            beforeSend: function (XMLHttpRequest) {

                //Specifying this header ensures that the results will be returned as JSON.           

                XMLHttpRequest.setRequestHeader("Accept", "application/json");

            },

            success: function (data, textStatus, XmlHttpRequest) {

                if (data && data.d != null) {

                    jSonArray.push(data.d);

                }

            },

            error: function (XmlHttpRequest, textStatus, errorThrown) {

                alert("Error :  has occured during retrieval of the contacts");

            }

        });

     

        return jSonArray;

    }

     

     

  • Arpine Sukiasyan Profile Picture
    180 on at

    Thanks

  • Community Member Profile Picture
    on at

    Hi, This is my jquery for retriving records but when i run this i get success but when i try to retrive records it shown

    [object] object 

    so any one can help me out on this?

    jQuery.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: "https://xxxxxxx.crm.dynamics.com/xrmservices/2011/OrganizationData.svc/Customer_RecordsSet?$select=CITY,Account_R&$top=1",
    async: false,
    beforeSend: function (XMLHttpRequest) {
    var x= XMLHttpRequest.setRequestHeader("Accept", "application/json");

    },
    success: function (data, textStatus, XmlHttpRequest) {
    if (data && data.d != null && data.d.results != null) {
    alert(data.d.results[0].Account_R);
    }
    },
    error: function (XmlHttpRequest, textStatus, errorThrown) {
    alert("Error : has occured during retrieval of the records ");
    }
    });

    Thanks!

  • Saroj Das Profile Picture
    3,355 on at

    Hi this thread is already answered. please start a new thread of your topic to get better answer.

    Please check this.

    if (data.d.results.length > 0) {

       //Do Something here

    }

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans