I'm trying to create an Invoice in the Invoice and Memo / ARInvoiceEntry Graph using BLC code. Here is the code I'm using:
ARInvoiceEntry arinventry = PXGraph.CreateInstance<ARInvoiceEntry>();
ARInvoice arinvoice = new ARInvoice();
arinvoice.DocType = "Invoice";
arinvoice.DocDate = DateTime.Now;
//Get the customer ID...
var cust = (Customer)PXSelect<Customer, Where<Customer.acctCD, Equal<Required<Customer.acctCD>>>>.Select(Base, CustomerCode); //"ABARTENDE");
if (cust != null)
arinvoice.CustomerID = cust.BAccountID;
//Get the project ID...
var proj = (PMProject)PXSelect<PMProject, Where<PMProject.contractCD, Equal<Required<PMProject.contractCD>>>>.Select(Base, JobNbr);
if (proj != null)
arinvoice.ProjectID = proj.ContractID;
//Insert the record...
arinventry.Document.Insert(arinvoice);
arinventry.Persist()
Every time I try this, I get the following error:
This does not happen when I enter the exact same data manually - the numbering sequence is set up correctly - this has been verified. The trace tells me nothing of any value, but here it is:
3/14/2023 2:36:41 PM Error:
CS Error: Cannot generate the next number for the sequence.
at PX.Objects.CS.AutoNumberAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)
at PX.Data.PXCache`1.PersistInserted(Object row, Boolean bypassInterceptor)
at PX.Data.PXCache`1.Persist(PXDBOperation operation)
at PX.Data.PXGraph.Persist()
at PX.Objects.AR.ARInvoiceEntry.Persist()
at HELInvoicesAndMemos.ARInvoiceEntryExt.GetInvoiceRecordsToIntegrate() in D:\Acumatica Customization projects\HELInvoicesAndMemos 22.112.0018\ARInvoiceEntryExt.cs:line 185
at HELInvoicesAndMemos.ARInvoiceEntryExt.b__4_0() in D:\Acumatica Customization projects\HELInvoicesAndMemos 22.112.0018\ARInvoiceEntryExt.cs:line 38
at PX.Data.PXLongOperation.<>c__DisplayClass18_0.b__0()
Am I missing something? I've done this kind of BLC code many times in the past with no problems.
Try this
arinvoice.DocType = "INV";
or better yet
arinvoice.DocType = ARInvoiceType.Invoice;