any way to query entity name by entity type code? RRS feed

  • Question

  • Hello, I have a design that generically supports different types of entities. This design involves passing an ObjectTypeCode parameter as part of a request to a manager class. 

    So, for example, if a request with ObjectTypeCode = 112 is passed to the manager class then the manager class treats the request as an incident request because CRM defines an incident as having ObjectTypeCode 112.

    I'm having problems using a QueryExpression for this. When I try to query "entity" or "entityview" through a QueryExpression, CRM returns the following error message:

    The entity with a name = '[entityname]' was not found in the MetadataCache

    Do you have any recommendations that I can follow to query an entity name by ObjectTypeCode?

    Friday, April 25, 2014 10:48 PM

All replies

  • Hi,

    I've found very few reasons to ever use ObjectTypeCodes - instead I try always to use entity logical names because these will not change between deployments. If you install your solution on a new organization you can't guarentee that your custom entities will get the same object type codes. There are ocationally places in Javascript where you need the object type code - but on the whole I'd recommend using the logical name in your custom code.

    If you absolutely need the object type code on the server you'll need to retrieve the entity metadata - you should always cache the value for performance reasons.

    Hope this helps,


    Scott Durow
    Blog www.develop1.net    Follow Me
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, April 27, 2014 2:16 PM
  • As Scott suggests, you can't use a QueryExpression to get this. Instead, you can use a RetrieveAllEntitiesRequest to get the entity metadata, and it would then make sense to cache this

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Monday, April 28, 2014 9:02 AM