Traversing the Account Tree

Mike Bray (Quote Loader Author)'s Avatar

Mike Bray (Quote Loader Author)

09 May, 2018 05:40 AM

I have hit an issue with traversing the tree of accounts. I thought that if you took the root account and traversed the tree by using:

    loadAccounts(Main.context.getRootAccount());

 private void loadAccounts(Account parentAcct) {
    int sz = parentAcct.getSubAccountCount();
    for(int i=0; i<sz; i++) {
      Account acct = parentAcct.getSubAccount(i);
      ..........
      loadAccounts(acct);
    }

You would eventually load every account in the file. This does not seem to be happening. I have added a Security and it is not appearing in the hierarchy. Is there a different way of traversing the tree?

  1. Support Staff 1 Posted by Sean Reilly on 09 May, 2018 09:23 AM

    Sean Reilly's Avatar

    Hi Mike,
    That does look like it should work, but only if the security was added to an investment account. If you'd like a list of all securities you can get them from the AccountBook's CurrencyTable. A security is only represented by an account if it is used by one or more investment accounts.

    Another way to iterate over all accounts is using the AccountIterator (https://infinitekind.com/dev/apidoc/com/infinitekind/moneydance/mod...). The account iterator or functions such as AccountUtil.allMatchesForSearch() would be a bit faster as it doesn't rely on traversing the account hierarchy.

    Thanks!

    Sean Reilly
    Developer, The Infinite Kind
    http://infinitekind.com

  2. 2 Posted by Mike Bray (Quot... on 09 May, 2018 03:45 PM

    Mike Bray (Quote Loader Author)'s Avatar

    Thanks Sean for the pointers. I will update my extensions accordingly.
    Mike

  3. Mike Bray (Quote Loader Author) closed this discussion on 15 Jun, 2018 02:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

02 Dec, 2024 12:49 PM
02 Dec, 2024 12:38 PM
02 Dec, 2024 11:29 AM
02 Dec, 2024 08:29 AM
02 Dec, 2024 07:08 AM