Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Count Attributes per entity

Posted on by 90

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

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,545 on at
    RE: Count Attributes per entity

    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.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Count Attributes per entity

    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");
    }
    }

  • Verified answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Count Attributes per entity

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans