How to prevent the increment of NextInvoiceNumber when the document number is manually set?

Hi all,

I have a situation where I need to set the document number of Sales Order Invoice programmatically and its a success. But the problem is, the NextInvoiceNumber keep incrementing even though it is not used for document number.

This is my setting for the invoice number. I will create my own sales order document number, and the invoice number is based on the sales order document number.

Is there any way to prevent the increment of NextInvoiceNumber when I don't even use it as invoice document number is my custom program?

  • 0

    How are you setting the SOPInvoiceCredit.DocumentNumber?

    The NextInvoiceNumber won't be incremented if

    1. the invoice number is assigned by processing the AssignInvoiceNumber message

    2. the SOPOrderReturn has document type Invoice or Credit (as in the Invoicing module)

    But if you're changing SOPInvoiceCredit.DocumentNumber after the invoice has been created by the SOPPrintInvCredCoordinator, it's too late,

    And if you're creating the SOPInvoiceCredit without the coordinator, you're braver than me!

  • 0 in reply to Geoff Turner

    Hi Geoff, I get a legacy project, where it is assigning the Invoice document no to match sales order document number as you see at the code below at line 7. This make sense when user want to print invoice in 1 file only.

    SOPInvoiceCredits credits = new SOPInvoiceCredits();
    credits.Query.Filters.Add(new Sage.ObjectStore.Filter(SOPInvoiceCredit.FIELD_SOPINVOICECREDIT, value));
    credits.Find();
    
    if (credits.First != null)
    {
        credits.First.DocumentNo = sop.DocumentNo;
        credits.First.SecondReference = sop.CustomerDocumentNo;
        credits.First.DocumentDate = sop.DocumentDate;
        credits.Update(); 
    }

    Now my user want to print multiple invoices in one file.

    So after I made the changes, the NextInvoiceNumber keep incrementing anyway. 

    From your answer I sense that changing the invoice document number is not recommended. so I will find another way. Thank you.