Is there any way to retrieve the ObjectTypeCode for a custom entity within the SDK
without requiring the user to have read permissions for entities in
their role security? I also don't want to do direct SQL reads due to other security issues with that. Thanks!
To get the ObjectTypeCode from a custom entity I retrieve EntityMetaData but this requires the user's role have read permissions on Entities. This is generally something I do when retrieving or adding notes, attachments, or activities to custom entities where I can't just hardcode the ObjectTypeCode. This is done from plugins as well as iframes, custom web pages, etc. thus the compiler directives for both plugins and non-plugins with the parameter.
Here is my code to retrieve the metadata.
public static EntityMetadata RetrieveEntity(
#if CRM_PLUGIN
IMetadataService metadataService,
#else
MetadataService metadataService,
#endif
string strLogicalName, bool boolFailIfMissing)
{
EntityMetadata entity = null;
try
{
RetrieveEntityRequest entityRequest = new RetrieveEntityRequest();
entityRequest.EntityItems = EntityItems.IncludeRelationships | EntityItems.IncludeAttributes;
entityRequest.LogicalName = strLogicalName.ToLower();
entityRequest.RetrieveAsIfPublished = false;
RetrieveEntityResponse entityResponse = (RetrieveEntityResponse)metadataService.Execute(entityRequest);
entity = entityResponse.EntityMetadata;
}
catch (SoapException ex)
{
WriteLog((boolFailIfMissing ? TraceLevel.Error : TraceLevel.Info),
string.Format("entity {0} does not exist.", strLogicalName + "\n" + ex.Detail.InnerText));
entity = null;
if (boolFailIfMissing)
throw ex;
}
return entity;
}
*This post is locked for comments
I have the same question (0)