Creating Transactions

Mike Bray 's Avatar

Mike Bray

06 Dec, 2019 10:29 AM

Has the way of creating transactions changed? I am creating a Miscinc transaction for an investment account and security. The sequence I am using is:
ptTran=ParentTxn.makeParentTxn(acctbook,date,date,currenttime,cheque,Investment Account,desc,memo,-1,ParentTxn.STATUS_UNRECONCILED)
stTran1.setParameter(AbstractTxn.TAG_INVST_SPLIT_TYPE, AbstractTxn.TAG_INVST_SPLIT_SEC)
stTran2.setParameter(AbstractTxn.TAG_INVST_SPLIT_TYPE, AbstractTxn.TAG_INVST_SPLIT_SEC)

The parent txn amount is coming out as negative and decreasing the running balance rather than increasing.

  1. 1 Posted by Mike Bray on 06 Dec, 2019 11:05 AM

    Mike Bray 's Avatar

    Changing the first amount on the split txn to -Amount seems to work. Is this the correct way of doing this?

  2. Support Staff 2 Posted by Sean Reilly on 06 Dec, 2019 11:50 AM

    Sean Reilly's Avatar

    Hi Mike,

    The best way to record, or edit, investment transactions is to use the InvestFields class. Create a new InvestFields object and set the various properties on it, or use the setFieldStatus(Txn) method with an existing transaction from the investment account. Once you've got the right properties into the InvestFields class then use the storeFields(Txn) method for it to apply the changes to the transaction you gave it, which could just be a new blank ParentTxn.


    Sean Reilly
    Developer/Director (

  3. 3 Posted by Mike Bray on 06 Dec, 2019 01:21 PM

    Mike Bray 's Avatar

    Great thanks Sean

  4. 4 Posted by Mike Bray on 07 Dec, 2019 11:34 AM

    Mike Bray 's Avatar

    Hi Sean

    Does storeFields(Txn) create the SplitTxns? I am getting a nullPointerException.


  5. Support Staff 5 Posted by Sean Reilly on 07 Dec, 2019 05:04 PM

    Sean Reilly's Avatar

    Hi Mike,
    Yes, storeFields(Txn) will automatically create the appropriate splits if they're not already in the transaction. Can you paste the NPE stack trace? You will need to make sure any required fields are there... I guess I don't have a helpful validator on it yet.


  6. 6 Posted by Mike Bray on 08 Dec, 2019 08:48 AM

    Mike Bray 's Avatar

    Hi Sean, I found my error. I have one last point. When I have transactions that are against the Investment Account rather than a Security (e.g. interest, management fee) I use the InvestTxnType.BANK and set the following fields:

    Amount (positive for income, negative for expense)
    hasAmount true
    Category (Interest or Management Fee)
    hasCategory true
    txnType InvestTxnType.BANK

    This creates the transactions but with a zero amount. Further testing and I changed 'category' and 'hasCategory' to 'xfrAcct' and 'has xfrAcct' it worked. I suppose using xfr as the transaction type would infer using the xfrAcct, however, the 'transfer' is to a category. Adding two new transaction types of 'Investment Income' and 'Investment Expense' would help.

  7. Support Staff 7 Posted by Sean Reilly on 08 Dec, 2019 10:32 PM

    Sean Reilly's Avatar

    Hi Mike,

    Hmm... I think you may need to set hasXfrAcct=true and set the xfrAcct to the expense category? Please let me know if that doesn't work.


  8. 8 Posted by Mike Bray on 09 Dec, 2019 08:45 AM

    Mike Bray 's Avatar

    Hi Sean

    I updated my post with that exact method which worked, see the updated post for a suggestion.

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


? 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