Traversing the Account Tree

Mike Bray (a user not support)'s Avatar

Mike Bray (a user not support)

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 (a us... on 09 May, 2018 03:45 PM

    Mike Bray (a user not support)'s Avatar

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

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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