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.
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.
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; } }
Hello,
Were you able to fix this issue? I also have the same requirement
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.
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; }
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