How to get Original Doc number from the ledger transactions in AX2012

I am pulling ledger transactions from the generaljournalaccountentry table for a report. I need to get the original document number (sales id, purch id,…etc) for these transactions. How do I achieve this? Thanks

I haven’t had a chance to work much on AX 2012 finance module, but the way how you can achieve this in, let’s say, AX 2009 is that you can track down CustTrans and VendTrans and other subledger transactions through the ledger voucher number.

Take a look at how ledger tracking works in standard AX. Open the Voucher transactions form and click on the button “Original document” and you’ll see that AX fills in a temporary table with records of voucher origin. I’d advise you to explore the class OriginalDocuments (though at the moment I can’t check if it is still available in AX 2012). You can initiate this class from your ledger transaction and the class will find all the subledger references (sales orders, purchase orders etc.) and save them in a temporary table for you.

Try this sample job (use your own LedgerTrans reference of course)

static void Job99(Args _args)


TmpLedgerBase tmpLedgerBase;

originalDocuments originalDocuments;

LedgerTrans ledgerTrans = LedgerTrans::findRecId(5646990926);


originalDocuments = new Originaldocuments(ledgerTrans);



while select tmpLedgerBase


info(strfmt("%1 = %2", tmpLedgerBase.OriginalDocument,;