2

Do you know is there any like a global reference book of MS CRM entities in the system?

I need to resolve entity id to the entity type without checking every single entity for presence of given GUID.

Is it possible?

shytikov
  • 9,155
  • 8
  • 56
  • 103
  • Can I ask why this requirement exists? Except for some SQL work it is very uncommon to have a record GUID with no other information such as logical name or object type code. – Nicknow Oct 08 '14 at 02:07
  • The requirements indeed very special one — is to find out to which entity `annotation` is linked to on pre-operation `Retrieve` of it. From the query definition it is possible to get the GUID of the referenced entity, but not type of it. – shytikov Oct 08 '14 at 06:30
  • If you are working on `annotation` you have an `ObjectTypeCode`. I've posted an answer below on how to query for entity logical name based on an OTC value. I recommend you update your question to better describe the actual requirement. – Nicknow Oct 08 '14 at 13:53

2 Answers2

1

I don't know of any supported way, but I believe you could to a SQL query on the PrincipalObjectAccess table in the database and retrieve the value of ObjectTypeCode where ObjectId is the GUID.

FireLeopard
  • 314
  • 4
  • 18
  • Actually it is possible to retrieve POA objects even via regular `OrganizatinService` calls, but it is still not valid approach through. I believe POA entries are not always created, i.e. if entity follows regular security approach, with no exception, like sharing creates... – shytikov Oct 08 '14 at 06:51
1

For annotation you need to look at the field objecttypecode to determine the entity type of objectid.

You can either generate a list of entity logical names and object type codes in your code as a Dictionary object (this will give you the fastest performance but requires you know all the entity types that will be in the system at the time you compile) or (if you are on CRM 2011 UR12+ or CRM 2013) you can do a MetadataQuery.

You can read more about doing a metadata query here: http://bingsoft.wordpress.com/2013/01/11/crm-2011-metadata-query-enhancements/

Sample code for your requirement:

var objTypeCode = [INTEGER] //Make this this the annotation.objecttypecode

MetadataFilterExpression entityFilter = new MetadataFilterExpression(LogicalOperator.And);
EntityFilter.Conditions.Add(new MetadataConditionExpression("ObjectTypeCode", MetadataConditionOperator.Equals, objTypeCode);
EntityQueryExpression entityQueryExpression = new EntityQueryExpression()
{
     Criteria = entityFilter
};
RetrieveMetadataChangesRequest retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest()
{
     Query = entityQueryExpression,
     ClientVersionStamp = null
};

RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)orgService.Execute(retrieveMetadataChangesRequest);

You can reduce the metadata retrieved, for better performance, as shown here: How to get the CRM Entity Name from the Object Type Code of a RegardingID?

Community
  • 1
  • 1
Nicknow
  • 7,154
  • 3
  • 22
  • 38