cancel
Showing results for 
Search instead for 
Did you mean: 

Error cancellingl A/R invoice through SDK

kinyanjuikamau
Explorer
0 Kudos

Hello all,

I am getting an error when trying to cancel an invoice through SDK.

The error is: System.NullReferenceException

The code is:

#region Cancel invoice

SAPbobsCOM.Documents sboCancel = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
sboCancel.GetByKey(docEntry);

SAPbobsCOM.Documents cancelDoc = sboCancel.CreateCancellationDocument();

int cancel = cancelDoc.Add(); <-- Error thrown here

if (cancel != 0)
{
ErrorLog.LoggerExceptionInfo(new Exception("Error " + oCompany.GetLastErrorDescription().ToString() + Environment.NewLine));
return;
}
else
{
ErrorLog.LoggerExceptionInfo(new Exception("Invoice cancelled for DocNum: " + item.DocNum));
}

#endregion

Any help appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi kinyanjuikamau,

Is it trying to Cancel the correct document?

Can you try the following?

if (sboCancel.GetByKey(docEntry))
{
// Do the operation.
}

Hope it helps!

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

Answers (0)