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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to show an accounts child account via the web api

(0) ShareShare
ReportReport
Posted on by 17

Hello All

Scenario: We are looking to use the dynamics api on an external application of ours. the requirment is when the user clicks on an account they are tehn taken to a list of all the child accounts.

I've been trying to build this out with the OData web api, though no luck. 

What i have achieved is to get the parents acount associated to a child account, but I'm really looking for the reverse here..

Its possible to do for the parent account as we can expand on the  parentaccountid lookup, though to do the reverse of this is where I'm stuck..

I envision it would be structured like below,

Account {

  

  ChildAccount {

  }

Anyway, i hope this makes sense and looking forward to what you have t say about this. 

Thanks

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    You can pass Account ID to get all child account using below web api code.

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/accounts?$select=accountnumber,name&$filter=_parentaccountid_value eq a16b3f4b-1be7-e611-8101-e0071b6af231", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                for (var i = 0; i < results.value.length; i  ) {
                    var accountnumber = results.value[i]["accountnumber"];
                    var name = results.value[i]["name"];
                }
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();

    Result - 

    • {
      • @odata.context:"">powerappsinfylearn.crm8.dynamics.com/.../$metadata,
      • value:[
        • {
          • @odata.etag:"W/"3574915"",
          • accountnumber:"1638847844",
          • name:"Test Shared Variable from C#",
          • accountid:"111359fc-9b04-eb11-a813-000d3af020c4"
          },
        • {
          • @odata.etag:"W/"3574525"",
          • accountnumber:"1718863253",
          • name:"Test account from UI",
          • accountid:"bc0732bb-9c04-eb11-a813-000d3af020c4"
          }
      }

    4721.CQ23.PNG

    Please mark my answer verified if i were helpful

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 > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans