locked
CRM 2011 problem with OData RRS feed

  • Question

  • Hi all,

    i have a following problem: I construct the ODATA_Final_url and when i use ODATA_Final_url1 it works fine (alert both values), when I use ODATA_Final_url2 it doesnt work (alerts undefined) - both urls return list xml in browser.

     

    Thanks for help


    function pocitadlo_get() {

            var ODATA_Final_url1 = "http://crm/TESTCRM/XRMServices/2011/OrganizationData.svc/SystemUserSet(guid'182cd05f-d34f-e011-9beb-000c298ac8da')";

            var ODATA_Final_url2 = "http://crm/TESTCRM/XRMservices/2011/OrganizationData.svc/SystemUserSet?$select=new_number,new_Prefix&$filter=SystemUserId%20eq%20guid'182cd05f-d34f-e011-9beb-000c298ac8da'";


             $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: ODATA_Final_url1,
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {

                    //This function will trigger asynchronously if the Retrieve was successful
                    var a = data.d.new_Prefix;
                    alert(a);
                    var b = eval(data.d.new_number);
                    alert(b);

                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert('Error: ' + ODATA_Final_url);
                }
            });
        }

    Friday, April 22, 2011 10:37 PM

All replies

  • Hi Jan,

    I tried the same in my machine it works. I think for you the user id might be wrong or the fields you specified in select are wrong.


    NarSr
    Monday, April 25, 2011 11:26 AM
  • The problem is, I querry same fields, only the URL changes. When I put the URL to browser it returns the values, but in javascript it alerts Undefined.

     

    Edit:

     

    So I have solved first part, the second URL returns an aray so you cant querry it like data.d.xyz but like this:

     

    function ProcessReturnedEntities(ManyEntities) {
            for (i = 0; i < ManyEntities.length; i++) {
                var oneEntity = ManyEntities[i];
                var prefix = oneEntity.lfc_Prefix;
                alert(prefix);
            }

     

    Now is my problem with updating the value, I use this (it is a value in related entity):

    working:

    var ODATA_Final_url = "http://crm/testjs/XRMServices/2011/OrganizationData.svc/new_counterSet(guid'c6b044af-226d-e011-a3de-000c296a524a')";

    not working:

    var ODATA_Final_url = "http://crm/testjs/XRMServices/2011/OrganizationData.svc/new_counterSet?%24filter=new_user_id/Id%20eq%20guid'182cd05f-d34f-e011-9beb-000c298ac8da'";

     

    I guess it is the same issue, I´m updating an aray and not only one field, could you help me how to



    function pocitadlo_post() {


            var ODATA_Final_url = "http://crm/testjs/XRMServices/2011/OrganizationData.svc/lfc_pocitadlo_nabidekSet(guid'c6b044af-226d-e011-a3de-000c296a524a')";

            var a = Xrm.Page.getAttribute("new_number").getValue() + 1;
            var entityObject = new Object();
            entityObject.new_number = a.toString();
            var jsonEntity = window.JSON.stringify(entityObject);

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                data: jsonEntity,
                url: ODATA_Final_url,
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                    XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
                },
                success: function (data, textStatus, XmlHttpRequest) {

                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                }
            });
        }

     



    Tuesday, April 26, 2011 8:06 AM