Lookup entity returned as object in .ByExpandQuery

May 17, 2013 at 10:56 PM
Edited May 17, 2013 at 10:58 PM
I'm trying to do a cross entity lookup for prepopulating information on a Quote Product from an associated Entity that is associated with the account. Naturally I need access to the account Id via the lookup entity. The problem is that the code returns only an object and I don't know how to crack that open to get at the data I need.

The first Alert returns an Object of type object, the second returns Undefined. I don't need to check to see if it is there, but rather I need to use it.
var filter2 = "QuoteId eq guid'" + quoteId + "'",
     columns2 = ['AccountId','quote_customer_accounts/AccountId'],
     relName2 = 'quote_customer_accounts';
    CrmRestKit.ByExpandQuery( 'Quote', columns2, relName2, filter2, false ).then( function ( data ) {       
        var set = data.d.results[0].quote_customer_accounts.results;

function onRestError( xhr, status, errorThrown ) {

            var msg = JSON.parse( xhr.responseText ).error.message.value;
This is similar to the discussion at this link:

.retrieve returning lookup to another entity
May 18, 2013 at 12:03 PM
Edited May 18, 2013 at 12:04 PM

the code looks correct but I like to test the code. Right now I am on vacation and do not have acces to an CRM environment...

Just to clarify the following line returns an object? :
Odd, this should be the Guide....

When you are using the IE Developer Toobar and add the "data.d.results[0].AccountId" to the watch you can examine the properties of the object.

Could you please make a screenshot of the watch of "data.d.results[0]" (expand all nodes) and post the screenshot here?

May 22, 2013 at 4:28 PM
Sometimes I forget the tools that are available. I never had a love for javascript. Expanding the object allowed for me to find this reference which does successfully get me the ID I was looking for. It was close I just didn't see how close.
This problem only comes up when the return value is a Lookup field. (Mainly AccountId but also CustomerId is not immune.)

This alert was able to return me the correct AccountId and I verified it already in the database to make certain it wasn't some other GUID being returned.

Thanks Daniel.