Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Retrieve Parent Account of an account

Posted on by 25

Hi.

I am new in dynamics crm. i want to create a custom workflow in which i can retrieve all parent accounts against one account.

How can i get this..?

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieve Parent Account of an account

    Using checking and retrieve won't be a good option here instead use fetchxml to fetch all the hierarchial data, keep in mind  follow limitation

    From SDK

    Recursion limits when querying hierarchical data

    Because querying hierarchical data can be resource intensive, there is a default limit of 100 recursions allowed conditions for hierarchical queries using the Above, AboveOrEqual, Under, UnderOrEqual, and NotUnder condition operators.

    These limits can be adjusted using Windows PowerShell commands through the deployment web service. More information:  TechNet: Administer the deployment using Windows PowerShell.

    OwnedByMeOrMyReports and OwnedByMeOrMyReportsAndTeams are hierarchical security condition operators that depend on the Hierarchy Depth setting that can be found in Settings > Security > Hierarchy Security. The value of this setting is stored in the Organization.MaxDepthForHierarchicalSecurityModel attribute.

  • Suggested answer
    ram r Profile Picture
    ram r on at
    RE: Retrieve Parent Account of an account

    Use Retreivemultiple instead of retrieve and make use of CRM FetchXML hierarchical querying. You can do an "above" or "equal or above" to get all parent accounts.

    Refer: exptechsolutions.blogspot.com/.../know-howdynamics-crm-365-query_12.html

  • Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Retrieve Parent Account of an account

    Hi Yasir,

    You just create one function for,

    Entity AccountDetails = service.Retrieve("account", AccountId, new ColumnSet("parentaccountid"));

    and return parentaccountid from function.

    Do add return value in arraylist. Once the last account not found parentaccount then terminate your code.

  • Yasir Ali Profile Picture
    Yasir Ali 25 on at
    RE: Retrieve Parent Account of an account

    Thanks Pravin,

    Can you send me some sample code hat how can i do this.....i am new in crm development.

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Retrieve Parent Account of an account

    Hi Yasir,

    That is the case you can do one thing like, you just store parent account in arraylist until and unless no parent account found.

    Regards, Pravin

  • Yasir Ali Profile Picture
    Yasir Ali 25 on at
    RE: Retrieve Parent Account of an account

    Suppose Account-1 has parent account Account-2 which has Account-3 as parent account. Account-3’s parent account is Account-4 which has no parent account ..

    so i want to retrieve all 3 parent accounts

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Retrieve Parent Account of an account

    Hi Yasir,

    Please do refer following code as a reference:

    IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

               IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               ITracingService tracingService = executionContext.GetExtension<ITracingService>();

               tracingService.Trace("Workflow started");

               Guid AccountId = context.PrimaryEntityId;

    Entity AccountDetails = service.Retrieve("account", AccountId, new ColumnSet("parentaccountid"));

    Using above code you can retrieve parent account lookup details.

    Hope this help you.... !!!!

    Regards, Pravin

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Retrieve Parent Account of an account

    Hello,

    Can you provide some details what is your actual requirement ?? why you are looking custom workflow ??

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