How can I post invoice journals in x++?

Hi,

I am trying to post an invoice journal in (Accounts payable/Area page in journals/Invoices/Invoice journal) and here is the code that I am using in a job

static void testInvoiceJournalPosting(Args _args)
{
    LedgerJournalCheckPost  jourCheckPost;
    LedgerJournalTable      jourTable;


    jourTable =  LedgerJournalTable::find('JR04161547');

    if (jourTable.RecId > 0)
    {
        jourCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(jourTable,
                                                                NoYes::Yes,
                                                                NoYes::Yes);
        // Post only if there is succesful validation.
        if (jourCheckPost.validate())
        {
            jourCheckPost.run();
        }
    }
}

But it is failing at the jourCheckPost.validate() line of code. It seems like the LedgerJournalCheckPost doesn’t have a parm method that takes LedgerJournalTable to pass in. It only takes the journalid. Am I missing something to add in my code?

Thanks,

Dave

Could you elaborate the problem, please?

What error do you get in validate() and at which line?

Why do you thing it’s related to a parm method?

Hi Martin,

The ledgeJournalTable buffer is empty in the Validate() method and it says that the journal doesn’t exist.

You shouldn’t be calling validate() by yourself - it’s called by runInternal(). Before calling validate(), runInternal() sets the value of ledgerJournalTable variable, which validate() methods depends on.

The run() method does all the required validation and don’t need to validate() before run() method,