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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

SDK.REST.retrieveMultipleRecords is not working

(0) ShareShare
ReportReport
Posted on by 1,532

Hi,

I have been working on this for a several hours.  I can't seem to see why this is not working.

function setSampleCodes() {

    var iselect = "$select=new_sampleid,new_name";
    var iorderby = "&$orderby=new_name";
    var options = iselect + iorderby;

    SDK.REST.retrieveMultipleRecords("new_sample", options, sampleCodeCallBack, errorHandler, retrieveComplete);
}

function sampleCodeCallBack(retrievedData) {
    var opt = new Option();
    if (retrievedData.length > 0) {
        for (var i = 0; i < retrievedData.length; i++) {
            opt[i].text = retrievedData[i].new_name;
            opt[i].value = retrievedData[i].new_Sampleid;
        }
        Xrm.Page.getAttribute("new_samplecode").setValue(opt);
    }
}

function retrieveComplete() {
    alert(Xrm.Page.gerAttribute("new_samplecodes").getValue());      
}

function errorHandler(error) {
    alert(error.message);
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi There,

    Its simple, Debug it - you will know where & on which exact line it is failing , also with what error.

  • rthompson Profile Picture
    1,532 on at

    I did the bugging.  It's seem to only return a null.  I can't seem to find the exact error message.

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi,

    When you say you did debugging, did you put a breakpoint in the callback function.

    What is the retrieveData.length?

    Also, not sure if this is the case, but in case it does retrieve data, what is the data type of new_sampleid? Is it an integer or a Guid.

    One more thing I notice. In your iselect, the new_sampleid is all lowercase. In your for loop (callback function) the S is uppercase. This must match.

    Hope this helps.

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Okay:

    1. try WebAPI instead - i doubt if Odata works in 2016 anymore.

    2. whatever you are trying to retrieve try to browse it in the browser by framing the odata URL.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello,

    Try to replace the code with WEB API like below - 

        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_samples?$select=new_sampleid,new_name&$orderby=new_name asc", true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var results = JSON.parse(this.response);
                    for (var i = 0; i < results.value.length; i++) {
                        var id = results.value[i]["new_sampleid"];
                        var name = results.value[i]["new_name"];
                    }
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();


    Change API version , if its different . 

    I have some doubt in your code  - What is the field  Type of new_samplecode, ? this is not the right way you are setting the value .

    function sampleCodeCallBack(retrievedData) {
        var opt = new Option();
        if (retrievedData.length > 0) {
            for (var i = 0; i < retrievedData.length; i++) {
                opt[i].text = retrievedData[i].new_name;
                opt[i].value = retrievedData[i].new_Sampleid;
            }
            Xrm.Page.getAttribute("new_samplecode").setValue(opt); 
        }
    }
  • rthompson Profile Picture
    1,532 on at

    Hi Goutam,

    Why should I use WEB API if  SDK.REST also works.  Is best practice to use WEB.API

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Yes its best practices to upgrade all our SDK dependency method because Microsoft introduce WEB API to reduce overhead of using SDK dependency . In future release MS will be deprecated the older way to retrieve data so its better to use the new WEB API instead of SDK.REST or XRMServiceToolKit.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans