web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Posting Payment from customer to LedgerJournal and mark invoice

(0) ShareShare
ReportReport
Posted on by

Hi.

I want to post payment to LedgerJournal and mark invoice for payment.

Example: customer '1104' has invoice '10002' with Saldo (Balance) 1000 USD.

I want to pay this invoice with 0.25 USD, so in Not payed invoices with apper line with this invoice with Saldo 999.75

So I use this code:

void clicked()
{
    LedgerJournalTable      header;
    LedgerJournalTrans      trans;
    LedgerJournalName       ledgerJournalName;
    CustTrans               custTrans;
    CustInvoiceJour         custInvoiceJour;
    NumberSeq               numberseq;
    LedgerJournalCheckPost  ledgerJournalCheckPost;
    ;

    select firstonly ledgerJournalName where ledgerJournalName.JournalType == LedgerJournalType::CustPayment;

    select custInvoiceJour where custInvoiceJour.InvoiceAccount=='1104' && custInvoiceJour.InvoiceId=='10002';

    print "custInvoiceJour=" + custInvoiceJour.InvoiceId;

    custTrans = CustTrans::findFromInvoice(custInvoiceJour.InvoiceId);

    if (!custTrans) print "custTrans not found";

    print "custTrans.RecId=" + int2str(custTrans.RecId);

    if (!CustTransOpen::findRefId(custTrans.RecId)) {
        error(strfmt("Invoice already payed: %1", custInvoiceJour.InvoiceId));
        return;
    }

    print "ledgerJournalName.Name=" + ledgerJournalName.Name;

    header.JournalName = ledgerJournalName.Name;
    header.JournalType = LedgerJournalType::Daily;
    header.Name = "JOURNAL_1";
    header.CurrencyCode = "USD";
    header.insert();

    print "journalNum = " + header.JournalNum;

    //numberseq = NumberSeq::NewGetVoucherFromCode(ledgerJournalName.VoucherSeries);

    trans.clear();
    trans.initValue();
    trans.JournalNum = header.JournalNum;
    //trans.Voucher = numberseq.voucher();
    trans.Voucher = "VOUCHER9";
    trans.TransDate = today();
    trans.AccountType = LedgerJournalACType::Cust;
    trans.AccountNum = custInvoiceJour.InvoiceAccount;
    trans.Txt = "COMMENT OF PAYMENT";
    trans.OffsetAccountType = LedgerJournalACType::Bank;
    trans.OffsetAccount = "USA OPER";
    trans.Dimension = ledgerJournalName.Dimension;
    trans.CurrencyCode = "USD";
    trans.ExchRate = 1.0;//ExchRates::find(header.CurrencyCode, datenull(), NoYes::No, NoYes::No).ExchRate;
    trans.TransactionType = LedgerTransType::Payment;
    trans.PaymMode = "Cash";
    trans.SettleVoucher = SettlementType::SelectedTransact;
    trans.MarkedInvoice = custInvoiceJour.InvoiceId;
    trans.AmountCurCredit = 0.25;
    print "trans.MarkedInvoice=" + trans.MarkedInvoice;

    trans.insert();

    ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(header, NoYes::Yes);
    ledgerJournalCheckPost.run();
}


In trans I use this two lines:

    trans.SettleVoucher = SettlementType::SelectedTransact;
    trans.MarkedInvoice = custInvoiceJour.InvoiceId;


which I expect to do this thing (mark invoice for payment). But I got error:

there are no marked transactions but for Settle type was chosen Selected Transactions (sorry for English, something like that)

Question is : what is wrong? How to mark invoice for payment in X++ code?

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,724 Super User 2026 Season 1 on at

    Hi Alexy,

    You need to mark invoices using the class SpecTransManager. This will link the journal line with the open customer transaction. There are some examples in standard AX how to use this class.

    It would be better to also use the classes JournalTableData and JournalTransData to fill the journal lines rather than writing the implementation on the tables directly. These classes will also execute some logic automatically to have data aligned as it was manually entered.

  • Community Member Profile Picture
    on at

    Hi, Andre.

    Thanks for advices.

    I am using now JournalTableData and JournalTransData.

    But i failed to find siutable examples how to use SpecTransManager. Can yo help me with this?

    I found examples like:

                specOffsetVoucher = SpecTransManager::construct(custTable);
                specOffsetVoucher.insert(invCustTrans.dataAreaId, invCustTrans.TableId, invCustTrans.RecId, invCustTrans.AmountCur, invCustTrans.CurrencyCode, NoYes::No);
                specOffsetVoucher.insert(payCustTrans.dataAreaId, payCustTrans.TableId, payCustTrans.RecId, payCustTrans.AmountCur, payCustTrans.CurrencyCode, true);
                specOffsetVoucher.updateMarkedPayment(payCustTrans.dataAreaId, payCustTrans.TableId, payCustTrans.RecId, true);


    but I did not understand how to use it in my case. As I understood it can be used only when Ledger is already posted.

    I did not understand how to use it when Ledger is not posted yet.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans