web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Count Attributes per entity

(0) ShareShare
ReportReport
Posted on by 92

Hi I have been trying to count the number of attributes per entity in a CRM 2016 environment. While there are some good things to aid this on XRM Toolbox there is nothing I can find that will give a total count.

Is there a SQL script out there that might help this or better still any documentation that gives an exact count on the total of OOB entity attributes? I.e, Account, contact, Case etc

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hello,

    You can query the MetaDataSchema.Attribute table in the <CRMORG>_MSCRM database if you are using CRM OnPremise. The query you'd need would be something like this :

    SELECT COUNT(DISTINCT AttributeId) from Attribute

    -> You need to use distinct as attributes are solution aware components and you can have multiple entries for the same AttributeId (different solutions that contain this component) but this doesn't add to the total count of attributes per entity.

    Another way to do this is via the SDK. An easy way to do it is via the CrmServiceClient:

    docs.microsoft.com/.../microsoft.xrm.tooling.connector.crmserviceclient.getallattributesforentity -> for a specific entity

    docs.microsoft.com/.../microsoft.xrm.tooling.connector.crmserviceclient.getallentitymetadata -> for all entity metadata

    Or you can use the RetrieveAllEntitiesRequest - docs.microsoft.com/.../gg327609(v%3dcrm.8)

    Keep in mind that you might see attributes that appear in the request but not in the UI - this is due to the fact that CRM uses also logical attributes for internal operations which can't be altered or deleted.

    Hope this helps,

    Radu

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    I dont see why you cant the following query on XrmToolBox Code Now plugin

    EntityQueryExpression entityQueryExpression = new EntityQueryExpression
    {
    Properties = new MetadataPropertiesExpression
    {
    AllProperties = false,
    PropertyNames = { "LogicalName", "DisplayName", "Attributes", "PrimaryIdAttribute", "ObjectTypeCode", "SchemaName" }
    },
    AttributeQuery = new AttributeQueryExpression
    {
    Properties = new MetadataPropertiesExpression(AttributeMetadataProperties)
    {
    AllProperties = false
    }
    },
    };

    RetrieveMetadataChangesRequest retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest
    {
    Query = entityQueryExpression,
    ClientVersionStamp = null
    };

    var response = (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest);


    Console.WriteLine("Entity attribute coutnts");

    if (response.EntityMetadata != null && response.EntityMetadata.Any())
    {
    foreach (var entityMetadata in response.EntityMetadata)
    {
    Console.WriteLine(entityMetadata.LogicalName + "has " + entityMetadata.Attributes.Count() + " attributes");
    }
    }

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at

    Hi,

    You can get the information related to Entity wise attributes in the below link

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/customize/create-edit-metadata

    If found useful, please mark this answer as verified answer.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans