Avoid exception of prompts being thrown using the SDK

SOLVED

I am trying to use the SDK to automatically add invoices from another system into my Sage 50 database.

for this, I use, the SalesJournal, check if an invoice with the same invoice number exists for the same customer, and if not, add the invoice.

Before adding the invoice, I clear the SalesJournal by calling Undo(). But an exception gets raised that says: "Are you sure you want to discard this transaction?"

I am not sure how I am supposed to answer to that question, or avoid the exception from being thrown.

I try working around the Undo() call and add an invoice to the database, but when calling Post(), then I get the exception: "The date for this transaction precedes the session date and will affect prior period reports. Are you sure you want to continue?".

So the invoice does not get added, and the API does not seem to present a way for me to answer that question, or force a "yes" answer to it.

How should I proceed to avoid those exceptions and be able to add my invoices as intended?

Thank you,

  • 0
    SUGGESTED
    Customer ID + Invoice number is a key field, so you may be able to trap the 'invoice already exists for this customer' exception instead of checking.

    I'm assuming the invoices don't arrive into Sage 50 in numerical order, or you could just check the value in tNxtPIDs for sales invoice number.
  • 0 in reply to RandyW
    verified answer
    Thanks for answering. I actually found the problem and what I had to do was provide my own implementation of the SDKAlert class ad use in the SDK by calling SDKInstanceManager.Instance.SetAlertImplementation(myAlertObject).

    The default SDKAlert throws exceptions for alerts from the SDK that require a decision. By overriding a few methods of the SDKAlert class, I could avoid exceptions from being thrown.

    Thanks!