Select an existing batch number



I have tried looking though out the forums for a way to select a batch number to use when trying to import invoices into Sage 100. What I have found was to use SelectBatch and pass the batch number I want to use as the parameter, but when I do I keep getting the error "<batch_no> already exists". Below is a snippit of the code I'm using in C# with Dispatch Object

DispatchObject pvx = new DispatchObject("ProvideX.Script");
DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session"));
string[] login = readProfileFromDisk();
object success = oSS.InvokeMethod("nSetUser", login[0], login[1]);

oSS.InvokeMethod("nSetCompany", ControllerConfiguration.HostCompanyCode);
oSS.InvokeMethod("nSetDate", "A/R", DateTime.Today.ToString("yyyyMMdd"));
oSS.InvokeMethod("nSetModule", "A/R");

int apInvoiceTaskID = (int)oSS.InvokeMethod("nLookupTask", "SO_Invoice_ui");
oSS.InvokeMethod("nSetProgram", apInvoiceTaskID);
DispatchObject invoice = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_Invoice_bus", oSS.GetObject()));

string batchNo = "5000";
//Fails Here
result = (int)invoice.InvokeMethod("nSelectBatch", batchNo);
if (result != 1) {
string message = invoice.InvokeMethod("sLastErrorMsg").ToString();

If batch 5000 doesn't exists, it creates a new batch fine in Sage 100 and everything works fine. Imports the invoice no problem.
But if I want to select the existing batch number 5000, I get the error "5000 already exists". If I try to ignore this message in case its actually just a warning and continue trying to import the invoice, after invoice.InvokeMethod("nSetKey") is called I get the error "A batch number is not set up." So I can assume here that it really did fail to set the Batch No. After that, get random error messages for nSetValue, most common being "Missing record to calculate taxes" and "You cannot use a credit card payment when credit card payment type is not set up." Ending with "This Invoice has no lines and has zero total amounts" after invoice.InvokeMethod("nWrite"), and yes I do add lines to the invoice.

If I change my batch number from 5000 to another number and try again, the invoice will import fine with none of the error messages above. Is there something I'm missing or are we not allowed to choose existing batch numbers when importing to SO_Invoice_ui?

  • 0

    That is odd, according to the docs, you should be ale to select an existing batch.

    SelectBatch( batchNo$ ), SelectNewBatch( batchNo$, private$, comment$ )

    This method selects the batch to work on, if this batch does not exist, the method will fail. If given no batch number, this method will create the next new batch and select it, passing back the batch number. If a new batch number is being created as private or with comments, then the SelectNewBatch() method should be used.



    object’SelectBatch( batchNo$ )

    object’SelectNewBatch( batchNo$, private$, comment$ )

    Parameters batchNo$

    (required) The number of the existing batch to work on. If left blank, this will create the next new batch and pass back the new batch number in this variable.


    (optional) Y to indicate that the batch to be created will be a private batch.



    (optional) Comments to be associated with the batch.



    On success: Returns 1.

    On failure: Returns 0.


    retVal = _obj’SelectBatch(“00002”)

    retVal = _obj’SelectNewBatch( batch$, “Y”, “new batch to be created”)

    Any 3rd party stuff?

  • 0

    I was having this same issue. I was working on the Issues in Inventory Management when I ran into this. It's because the batch number is 4 digits for some reason. I had a script and just padded left to make it 5 digits and it started working. Interestingly if the batch number is 4 digits and you attempt to look in Sage for it, the line items will not appear but it will be in the database and you will have to delete it from there.