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

Notifications

Announcements

No record found.

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
    301,069 Super User 2025 Season 2 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans