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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

X++ Post Free Text Invoice with Manual Assigned Invoice ID

(0) ShareShare
ReportReport
Posted on by 1,214

Hi,

I'm learning on using the CustPostInvoice class to post free text invoice. But is it possible to manually assigned the Invoice ID without relying on the system generated number sequence?

Thank you.

I have the same question (0)
  • Ludwig Reinhard Profile Picture
    33 Microsoft Employee on at

    Hello Hairul,

    The FTI invoice number is assigned at the time you post.

    Why is it that you want to chose a different number?

    Best regards,

    Ludwig

  • Suggested answer
    WillWU Profile Picture
    22,359 on at

    Hi HAIRUL HAZRI,

    There is a field called ManualInvoiceID_W on the table CustInvoiceTable,  but it applies to specific countries.

    You can check the getNumAndVoucher_W method in the CustPostInvoice class and refer to the logic of the method:

      private container getNumAndVoucher_W(NumberSeq _numberSeq)
        {
            container ret;
    
            if (custInvoiceTable.ManualInvoiceID_W != '')
            {
                _numberSeq.parmNumberSequenceCode('');
                _numberSeq.parmNumberSequenceId(0);
    
                ret = [custInvoiceTable.ManualInvoiceID_W, _numberSeq.voucher()];
            }
            else
            {
                if (custInvoiceTable.ManualNumbering_W)
                {
                    if (!LtInvoiceAutoNumberingTable::checkLastDate(custInvoiceTable.DocNumberingCode_LT, custInvoiceTable.InvoiceDate, true))
                    {
                        throw error("@SYS25904");
                    }
    
                    _numberSeq.parmNumberSequenceCode('');
                    _numberSeq.parmNumberSequenceId(0);
                    ret = [NumberSeq::newGetNumFromCode(LtInvoiceAutoNumberingTable::find(custInvoiceTable.DocNumberingCode_LT).NumberSequenceCode).num(),
                           _numberSeq.voucher()];
    
                    LtInvoiceAutoNumberingTable::updateLastDate(custInvoiceTable.DocNumberingCode_LT, custInvoiceTable.InvoiceDate);
                }
                else
                {
                    ret = _numberSeq.numAndVoucher();
                }
            }
    
            return ret;
        }

    pastedimage1614670404151v1.png

  • HAIRUL HAZRI Profile Picture
    1,214 on at

    Hi Ludwig,

    we are importing posted free text invoice from different system. The import file will include the Invoice ID from that system. Hence, we want to post free text invoices in D365 with those specific Invoice ID.

    Since posting Purchase Order Invoices and Sales Order Invoices are doable that way, we thought free text invoices should be doable too.

  • Maverick Profile Picture
    182 on at

    Hello,

    Were you able to fix this issue? I also have the same requirement

  • Suggested answer
    HAIRUL HAZRI Profile Picture
    1,214 on at

    Try this extension of class CustPostInvoice.

    This is working for me. But note that the standard free text invoice number sequence will always be counted.

    [ExtensionOf(ClassStr(CustPostInvoice))]
    final class CustPostInvoice_Extension
    {
        protected container getInvoiceIdAndVoucher(CustInvoiceTable _custInvoiceTable, NumberSeq _numberSeq)
        {
            //boolean                          countryRegion_LTLV = (this.countryRegion == #isoLT || this.countryRegion == #isoLV);
            InvoiceId                        _invoiceId;
            Voucher                          _voucher;
            NumberSeq                       newNumSeq;
            boolean                         creditNote;
            CustFreeInvoiceCalcTotals custFreeInvoiceCalcTotals;
    
            next getInvoiceIdAndVoucher(_custInvoiceTable, _numberSeq);
    
            custFreeInvoiceCalcTotals = this.custFreeInvoiceCalcTotals;
            creditNote = this.isCreditNote(custFreeInvoiceCalcTotals.custFreeInvoiceInvoiceAmount());
    
            if (!this.validate(custFreeInvoiceCalcTotals.custFreeInvoiceInvoiceAmount(), creditNote))
            {
                Message::Add(MessageSeverity::Error, "@SYS25904");
                throw Exception::Error;
            }
    
            newNumSeq = this.allocateNumAndVoucher(creditNote);
    
            if (_custInvoiceTable.ManualInvoiceID)
            {
                [_invoiceId, _voucher] = this.getNumAndVoucher(newNumSeq);
                if (! CustInvoiceJour::checkDuplicateNum_W(_invoiceId, '', custInvoiceTable.InvoiceDate))
                {
                    throw error("@SYS25904");
                }
            }
            else
            {
                [_invoiceId, _voucher] = newNumSeq.numAndVoucher();
            }
    
            if (custInvoiceTable.InvoiceId
                && RetailMCRChannelTable::findForCurrentUser().mcrEnableOrderCompletion)
            {
                _invoiceId = custInvoiceTable.InvoiceId;
                _voucher = custInvoiceTable.mcrLedgerVoucher;
            }
    
            if (!_voucher)
            {
                throw error("@SYS71652");
            }
    
            return [_invoiceId, _voucher];
        }
    
        private container getNumAndVoucher(NumberSeq _numberSeq)
        {
            container ret;
    
            if (custInvoiceTable.ManualInvoiceID != '')
            {
                _numberSeq.parmNumberSequenceCode('');
                _numberSeq.parmNumberSequenceId(0);
    
                ret = [custInvoiceTable.ManualInvoiceID, _numberSeq.voucher()];
            }
            else
            {
    
                ret = _numberSeq.numAndVoucher();
    
            }
    
    
            return ret;
        }
    
    }

  • Haroon Ghazanfar Profile Picture
    10 on at
    you said         "   Since posting Purchase Order Invoices and Sales Order Invoices are doable that way, we thought free text invoices should be doable too.     "         can you help me how this is doable in posting sale order invoices . because when i try to import InvoiceId through excel with both Customer Invoice and Customer Invoice Voucher manual . it gives error of "voucher number must be filled in".       can you help me in doing so . thanks in advance.

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

News and Announcements

[Smoke test 2510.1]

Quick Links

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans