Skip to Content
0
Apr 03, 2020 at 04:30 PM

Cancel AR Invoice with DI API - Error -5002

333 Views Last edit Apr 03, 2020 at 08:50 PM 2 rev

Hi

I am trying to cancel a AR Invoice with following code via DI-API with it returns error -5002 (Date deviates from permissible range).

I have made sure that the document settings allow cancelled documents at any time.


We are on 9.3 PL9. The code is below. Can anyone cast any light on this as it seems to be a common question that has gone unanswered here.

Many thanks!

SAPbobsCOM.Documents Invoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
            SAPbobsCOM.Documents cInvoice = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);


            Invoice.GetByKey(999);


            cInvoice = Invoice.CreateCancellationDocument();
            cInvoice.CancelDate = DateTime.Now;
            var value = cInvoice.Update();


            if (value != 0)
            {
                MessageBox.Show("Error: " + oCompany.GetLastErrorCode() + " // " + oCompany.GetLastErrorDescription());
            } else
            {
                MessageBox.Show(sErrMsg);
            }