简体   繁体   中英

Retrieving Records From Entity in Dynamics Crm using odata and jquery

I want to print the values retrieved from my entity in an alert message.I store the values in relatedproduct array i want to print these value.When it try to print them it gives undefined message.Plz help me

    relatedProducts = [];

    function onload() {
       var oDataUri="https://yanceyworksllc.crm.dynamics.com/xrmservices/2011/OrganizationData.svc/ProductSet?$select=new_price,ProductId&$filter=new_TaxInformation/Value eq 1";
       GetRecords(oDataUri);
       var totalRecords = relatedProducts .length;
    }

    function GetRecords(url) {
        jQuery.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: url,
            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) {
                    AddRecordsToArray(data.d.results);
                    FetchRecordsCallBack(data.d);
                }
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
             //  FetchRecordsCallBack(data.d);
                alert("Error :  has occured during retrieval of the records ");
            }
        });
    }

    function AddRecordsToArray(records) {
        for (var i = 0; i < records.length; i++) {
            relatedProducts .push(records[i]);
           alert(relatedProducts[i].Value) ;

        }

    }

    function FetchRecordsCallBack(records) {
        if (records.__next != null) {
            var url = records.__next;
            GetRecords(url);
        }
    }

A very easy way to troubleshoot OData calls is to copy the URI into your browser and navigate to the page. If it does not bring you to a page with data, that means your uri is wrong. If it does, then you are handling the resulting data incorrectly (ie if the debugger hits the success block in GetRecords, then your AddRecordsToArray or FetchRecordsCallBack is broken).

Side note - I have never seen a space before a ".[Attribute Name]". Is that even a valid JavaScript syntax (as in your relatedProducts .push or relatedProducts .length)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM