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.