Skip to main content
Answer

Creating a prepayment invoice

  • November 21, 2025
  • 2 replies
  • 34 views

Forum|alt.badge.img+1

Hello, this should be simple but I’m struggling. 

This code will create an invoice, and work perfectly.

private ARInvoice CreatePrepaymentInvoice1(SOOrder order, decimal amount)
{
ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
ARInvoice invoice = graph.Document.Insert(new ARInvoice
{
DocType = ARDocType.Invoice,
CustomerID = order.CustomerID,
DocDate = Base.Accessinfo.BusinessDate,
});
graph.Save.Press();
return graph.Document.Current;
}

Switch the DocType to Prepayment and now it doesn’t work. 

private ARInvoice CreatePrepaymentInvoice1(SOOrder order, decimal amount)
{
ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
ARInvoice invoice = graph.Document.Insert(new ARInvoice
{
DocType = ARDocType.Prepayment,
CustomerID = order.CustomerID,
DocDate = Base.Accessinfo.BusinessDate,
});
graph.Save.Press();
return graph.Document.Current;
}

The error is:
“CS Error: Cannot generate the next number for the  sequence.”

In the UI, I can open the invoice screen, select Prepayment, select a customer and click save. No problem.

Can anyone explain what is happening? Why this isn’t working? How I should change the code to make it work?

Best answer by dgranger70

Shouldn’t a prepayment be inserted using the ARPaymentEntry graph instead of the ARInvoiceEntry graph?

2 replies

Forum|alt.badge.img
  • Varsity I
  • Answer
  • November 21, 2025

Shouldn’t a prepayment be inserted using the ARPaymentEntry graph instead of the ARInvoiceEntry graph?


Forum|alt.badge.img+1
  • Author
  • Varsity III
  • November 21, 2025

@dgranger70 You are correct. I’m really wanted to create a PrepaymentInvoice, not a Prepayment, and strangely enough, when you change DocType = ARDocType.Prepayment to DocType = ARDocType.PrepaymentInvoice, it works! 

private ARInvoice CreatePrepaymentInvoice1(SOOrder order, decimal amount)
{
ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
ARInvoice invoice = graph.Document.Insert(new ARInvoice
{
DocType = ARDocType.PrepaymentInvoice,
CustomerID = order.CustomerID,
DocDate = Base.Accessinfo.BusinessDate,
});
graph.Save.Press();
return graph.Document.Current;
}

I’ve wasted way too long in this.