0
votes

I am writing an app which uses XRM SDK to get data from MS CRM 11. For fields of type lookup I want to get their corresponding definition so I can retrieve all possible ids and values from the related entity.

I cannot seem to find a way to get this. I understand I can get the entity reference for an entity instance value and how to get target entities from meta data but cannot find anything to help me get all lookup ids and values for a lookup field. Please help!

Edit:

In the interest of helping others, and after several more days investigation, I am convinced what I want to do is not possible server-side using sdk.

I can get pick list values no problem using a RetrieveAttributeRequest and cast the resulting AttributeMetaData to PicklistAttributeMetadata. You can use the same technique to deal with Lookups by casting to LookupAttributeMetadata but this only gives you one useful property over the base class: Targets. All this does is provide a string array of entity logical names. It gives you no additional detail such as mapped Id/Name properties or any view details for lookups where queries are applied (such as primary contact lookups where contacts listed are for current organisation).

So, in the end I have had to compromise. I can get the target entity name from Targets and assume that the lookup is simple - just pull all records from entity. The Id column is fixed so that is ok and generally you are safe to assume the Name column is available (albeit likely asl_name etc. if custom).

If anyone knows a better way I will gladly, willingly eat humble pie!

1
Seriously I thought that too! I've searched for hours and reached desperation point. I'm at the point of conceding defeat but this seems such a simple thing that I cannot believe no one else has required it, hence a last ditch effort by asking the question.user3059235
Come on, just look at the CRM SDK and you'll find a way out to it. There are ample of examples in the SDK itself that should give you the results.Piyush
Just to clarify I am not asking this question because I haven't looked. I have spent hours going through the SDK samples and trawling the internet. I am new to integration with Crm (but not development) so it is definitely true I could be missing something really obvious - hence my call for help. It is not because I am lazy and just expect others to do my work for me, but completely concede I am probably missing something obvious. A simple pointer from someone or at least a confirmation that it is possible would help.user3059235

1 Answers

0
votes

I believe what you're trying to do is fetch all records of a particular entity after you have retrieved the entity name using the metadata service.

If that is what you are looking to do, I suggest having a look at the following location in the SDK (I am referring to the SDK for CRM 2013) SDK\SampleCode\JS\RESTEndpoint\JQueryRESTDataOperations\JQueryRESTDataOperations\Scripts for the file JQueryRESTDataOperationsSample.js

There's this function called RetrieveMultiple which you can use to fetch all records of a particular entity by providing the Entity Name and any filters (optional). If you need help creating the oData query for the filters, you can download the oData Query Deisgner to form the query.