Hello,
We recently ran into a problem while importing AP invoices as a batch. Here is a summary of our code in C#:
// Loop though AP invoices a batch
foreach (var invoice in batch.NonInventoryInvoices) {
try {
service.Call("nCLEAR");
service.SetKeyValue("APDivisionNo$", invoice.APDivisionNo);
service.SetKeyValue("VendorNo$", invoice.VendorNo);
service.SetValue("InvoiceAmt", invoice.Total);
service.SetValue("NetInvoiceAmt", invoice.Total);
... Set all other values
} catch (Exception exception) {
var exceptionWithInformation = service.AddErrorInformationTo(exception); // Grabs sLastErrorNum and sLastErrorMsg
...
}
...
}
And in service, methods such as `Call` and `SetValue` are wrapped in a try catch so that it will catch the `TargetInvocationException` thrown through reflection method.
Here is the scenario that we couldn't figure out:
In a batch of invoices, for Invoice Number 1: the BOI throws an error for a legitimate reason, for example the vendor doesn't exist, the TargetInvoicationException's inner exception would be : "<Error: 0 in Method SETVALUE>" and sLastErrorNum is "CI_Required" and sLastErrorMsg is "The Vendor Number is required." . This is totally understable and we swallow the exception and continue to try to import the next invoice.
The problem is for all the subsequent invoices, the call fails at `service.Call("nCLEAR");`, the inner exception for TargetInvoicationException's is '{"<Error: 0 in Method CLEAR>"}' and the sLastErrorNum and sLastErrorMsg is the same.
The reason for us calling `CLEAR` at the beginning of each invoice is that we had a bug before where in a batch of invoices, one invoice fails and the subsequent invoice inherent ed information from the previous invoice, so we make sure CLEAR is performed before entering each invoice.
Thank you for your help!
Tom