Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

How to find Positional Hierarchy is enabled in Dynamics CRM programmatically using C#?

Posted on by 5

Hi Community,

We have a requirement where we need to find if positional hierarchy is enabled in Dynamics CRM using C# code.

Also we need to check for the list of excluded tables in the hierarchy using C#.

It would be really helpful to us if we get any solution regarding our above queries.

Thanks and regards.

  • RE: How to find Positional Hierarchy is enabled in Dynamics CRM programmatically using C#?

    Thanks a ton! R@y .

    Your answer really helped us alot.

    Regarding the enable hierarchy option of Dynamics CRM, i did some research of my own and got the answer.

    Thanks and regards,

    Bharat.

  • Verified answer
    Ray Profile Picture
    Ray 1,505 on at
    RE: How to find Positional Hierarchy is enabled in Dynamics CRM programmatically using C#?

    Hi Bharat,

    There is an attribute in organization entity/table usepositionhierarchy, you can check this attribute.

    There is a(n) entity/table hierarchysecurityconfiguration. All the tables excluded from the hierarchy will have a record in this table.

    Here is the example code to retrieve all the records:

    // query if hierarchy is enabled
    var queryOrg = new QueryExpression("organization");
    queryOrg.NoLock = true;
    queryOrg.TopCount = 1;
    queryOrg.ColumnSet = new ColumnSet("usepositionhierarchy");
    var organizationEntityCollection = OrgService.RetrieveMultiple(queryOrg);
    var usePositionHierarchy = organizationEntityCollection.Entities.First().GetAttributeValue("usepositionhierarchy");
    // query execlued entity
    var query = new QueryExpression("hierarchysecurityconfiguration");
    query.NoLock = true;
    query.ColumnSet = new ColumnSet(true);
    var excludedEntityCollection = OrgService.RetrieveMultiple(query);


    configuration screenshot:

    pastedimage1660115281029v1.png

    Query result with SQL 4 CDS tool:

    pastedimage1660116279870v1.png

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans