object OBJECT RRS feed

  • Question

  • I have an entity areacodes which contains a lookup field to a related entity, I cant get my head around how to retrieve the guid or textvalue:

     var serverUrl = document.location.protocol + "//" + document.location.host + "/" + 
        var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
        oDataEndpointUrl += "a_areacodeSet?$select=a_BD,a_DS,a_PS, a_bdsalesarea, a_psalesarea, a_txtPostcode, a_helifixterritory, a_hsalesmanager&$filter=a_txtPostcode eq '" + postcodeArea + "'";
        var service = GetRequestObject();
        if (service != null)
            service.open("GET", oDataEndpointUrl, false);
            service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
            service.setRequestHeader("Accept", "application/json, text/javascript, */*");
            var requestResults = eval('(' + service.responseText + ')').d;
            if (requestResults != null && requestResults.results.length > 0)
                SetOptionsetValue("o_pareacode", requestResults.results[0].a_PS);
    alert("a_bdsalesarea : " + requestResults.results[0].a_bdsalesarea);
    alert("a_pssalesarea : " + requestResults.results[0].a_psalesarea);

    The alerts at the bottom both show[object OBJECT] I am wanting to retrieve the id and values from these, but how?


    Wednesday, September 7, 2016 11:00 AM

All replies

  • var requestResults = eval('(' + service.responseText + ')').d;

    replace with

    var requestResults = JSON.parse(service.responseText).d;


    The JavaScript Object Notation (JSON) format is used for serializing and transmitting structured data much in the same way that XML is typically used.

    Like XML, it’is text based and designed to be readable by humans. To convert regular JavaScript objects into the JSON format you use the JSON.stringify method.

    Because the text in JSON defines JavaScript objects, the text could be converted to JavaScript objects by using the eval method.

    However, this practice creates security vulnerabilities.

    You should use theJSON.parse method instead.

    Hope this helps.


    • Edited by Suresh Sorde Thursday, September 8, 2016 9:07 AM
    • Proposed as answer by Suresh Sorde Thursday, September 8, 2016 9:28 AM
    Wednesday, September 7, 2016 11:59 AM