6

Running into this issue in Dynamics 365 that seems like it should be working, but gives me:

Property '_biz_buyerlookupid_value' on type 'Microsoft.Dynamics.CRM.biz_productbuyer' is not a navigation property or complex property. Only navigation properties can be expanded.

I can copy the example provided here and it works find:

https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/query-data-web-api#retrieve-related-entities-by-expanding-navigation-properties

Basically trying to read in related fields so I don't have to do another query.

So I have a look up field in a custom entity called Product Buyer, or biz_productbuyers, to bring in the Contact name associated with that Product.

The field is called biz_buyerlookupid when you look at fields for the entity.

When you use the web API, it says nothing called biz_buyerlookupid exists in that entity. Get rid of the $select= and run it wide open so I can search for it.

There is a field called _biz_buyerlookupid_value. I put that into the $select and it returns:

{
    @odata.etag: "W/"20636204"",
    _biz_buyerlookupid_value: "906595fd-2a83-dc11-ae20-000feaed3854",
    biz_productbuyerid: "8be67d14-9efb-4335-98c7-000451a50cef",
}

Apparently some kind of relationship between the two fields, but it sounds like the _biz_buyerlookupid_value is the lookup to Contacts. The _biz_buyerlookupid_value does correspond with an actual value in the contact entity, namely a single contactid. I checked. Have tried all of the following and have received the preceding message:

/api/data/v9.0/biz_productbuyers?$select=_biz_buyerlookupid_value&$expand=_biz_buyerlookupid_value($select=contactid, fullname)

/api/data/v9.0/biz_productbuyers?$select=_biz_buyerlookupid_value&$expand=biz_productbuyerid($select=contactid, fullname)

/api/data/v9.0/biz_productbuyers?$select=biz_productbuyerid&$expand=biz_productbuyerid($select=contactid, fullname)

/api/data/v9.0/biz_productbuyers?$select=biz_productbuyerid&$expand=_biz_buyerlookupid_value($select=contactid, fullname)

So what is going on here? It should be bringing in the contactid and fullname from the contact entity as best as I can tell.

cjones
  • 8,384
  • 17
  • 81
  • 175

1 Answers1

11

My understanding is that the _[field]_value item will give you the GUID of the associated item immediately.

To use $expand you have to use the schema name, so it should look like:

$expand=biz_buyerlookupid($select=contactid, fullname)

and note that biz_buyerlookupid is case sensitive.

You can look at the metadata for the CRM instance to get the correct casing: https://[org].crm.dynamics.com/api/data/v9.0/$metadata

jasonscript
  • 6,039
  • 3
  • 28
  • 43
  • Looking at the `$metadata` was incredibly helpful! From there I could look at the `` and then look at the `` associated with the lookup. From there I got the actual name it is using which does appear to be the schema name. Working now! – cjones Dec 13 '18 at 23:45
  • 2
    Bonus: for anyone needing it in the future, you can combine multiple expands like `$expand=schema_name1($select=field),schema_name2($select=field)`. – cjones Dec 13 '18 at 23:57
  • This was driving me nuts, and that metadata link has really opened my eyes and explained some stuff (which really should be visible in the UI somewhere). Time to consolidate all my power automate queries and use expand instead! – Paul F Oct 20 '21 at 12:14
  • "note that [...] is case sensitive." Wow... just wow. Thanks sir. – Tipx Jun 12 '23 at 17:42