tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/2150-traversing-the-account-treeInfinite Kind: Discussion 2018-06-15T14:34:26Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/452501442018-05-09T05:40:18Z2018-05-09T05:40:18ZTraversing the Account Tree<div><p>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:</p>
<pre>
<code> 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);
}</code>
</pre>
<p>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?</p></div>Mike Bray (Quote Loader Author)tag:infinitekind.tenderapp.com,2009-01-14:Comment/452501442018-05-09T09:23:10Z2018-05-09T09:23:10ZTraversing the Account Tree<div><p>Hi Mike,<br>
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.</p>
<p>Another way to iterate over all accounts is using the AccountIterator (<a href="https://infinitekind.com/dev/apidoc/com/infinitekind/moneydance/model/AccountIterator.html">https://infinitekind.com/dev/apidoc/com/infinitekind/moneydance/mod...</a>). The account iterator or functions such as AccountUtil.allMatchesForSearch() would be a bit faster as it doesn't rely on traversing the account hierarchy.</p>
<p>Thanks!</p>
<p>Sean Reilly<br>
Developer, The Infinite Kind<br>
<a href="http://infinitekind.com">http://infinitekind.com</a></p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/452501442018-05-09T15:45:31Z2018-05-09T15:45:31ZTraversing the Account Tree<div><p>Thanks Sean for the pointers. I will update my extensions accordingly.<br>
Mike</p></div>Mike Bray (Quote Loader Author)