Alternative to getAccountByName()

I need to get / lookup an account by its system ID/Key (I assume it has one?). I can only find getAccountByName(). There is a getAccountNum() but it says 'don't use this, it's stupid'. I can't see that looking up by a text name is 'safe'. For example, I have two account with the same name (for testing). Please advise how to return an Account's 'key' and the correct method to then lookup the Account using that key? Many thanks

  1. 1 Posted by Mike Bray on 01 Oct, 2020 07:50 AM

    Mike Bray 's Avatar

    Use AccountBook.getAccountByUUID(String acctID).  Moneydance changed the
    numbering system I think in version 2015, the getAccountNum() is for
    accounts created before.  All records within MD have a UUID which is in
    the SyncableItem class which all records extend.  Account.getUUID()
    returns the account's UUID.

  2. 2 Posted by Stuart Beesley ... on 01 Oct, 2020 07:52 AM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    Thanks Mike, that make sense. But now given that I have an Account’s UUID, is there a method I can call to retrieve the account?

    So if I know that an Account’s UUID is 123; can I call .getAccountByUUID(123) to return the account? I cannot find such a method?

    THanks

  3. 3 Posted by Stuart Beesley ... on 01 Oct, 2020 08:00 AM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    I think I found it....:
    AccountUtil.findAccountWithID​(Account root, java.lang.String accountUUID)
    Can someone confirm this is OK in conjunction with AccountBook.getAccountByUUID(String acctID).?

    (I'm learning that in the API Docs you need to look at the inherited Methods section too!)

  4. 4 Posted by Stuart Beesley ... on 01 Oct, 2020 10:14 AM

    Stuart Beesley - JUST A FELLOW USER's Avatar

    I've confirmed this works. Thanks

  5. Stuart Beesley - JUST A FELLOW USER closed this discussion on 01 Oct, 2020 10:14 AM.

  6. Mike Bray re-opened this discussion on 01 Oct, 2020 01:10 PM

  7. 5 Posted by Mike Bray on 01 Oct, 2020 01:10 PM

    Mike Bray 's Avatar

    It is on the AccountBook as per my post

  8. Support Staff 6 Posted by Sean Reilly on 01 Oct, 2020 03:11 PM

    Sean Reilly's Avatar

    As Mike says, the AccountBook.getAccountByUUID() method is the one to use. If you'd like a permanent reference to any kind of object you can also use the objects .getUUID() method, and use AccountBook.getItemForID(String uuid) to retrieve it again.

    Cheers,
    Sean

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

  9. Maddy closed this discussion on 02 Oct, 2020 12:05 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