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 :
Finance | Project Operations, Human Resources, ...
Suggested answer

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

(0) ShareShare
ReportReport
Posted on by 1,202

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.

  • Suggested answer
    HAIRUL HAZRI Profile Picture
    1,202 on at
    RE: X++ Post Free Text Invoice with Manual Assigned Invoice ID

    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;
        }
    
    }

  • Maverick Profile Picture
    180 on at
    RE: X++ Post Free Text Invoice with Manual Assigned Invoice ID

    Hello,

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

  • HAIRUL HAZRI Profile Picture
    1,202 on at
    RE: X++ Post Free Text Invoice with Manual Assigned Invoice ID

    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.

  • Suggested answer
    WillWU Profile Picture
    22,342 on at
    RE: X++ Post Free Text Invoice with Manual Assigned Invoice ID

    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

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: X++ Post Free Text Invoice with Manual Assigned Invoice ID

    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

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

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

Product updates

Dynamics 365 release plans