Getting error "Unable to select this batch. This batch was created in Invoice Data Entry." from SO_Shipping_BUS

SUGGESTED

I am trying to create a new batch and use the SO_Shipping_BUS object to process a sales order automatically through Shipping Data Entry.

The code works if I use SO_Invoice_BUS, but not for SO_Shipping_BUS.  When I try to set the invoiceNo key, I get the error message "Unable to select this batch. This batch was created in Invoice Data Entry."

I can see that my batch is created in the database table GL_CompanyActiveBatch and the BatchSubType column contains an "S" which should be correct for SO_Shipping_BUS and the UI Shipping Data Entry, so I am not sure why it thinks that the batch was created through "Invoice Data Entry" which puts an "I" in BatchSubType.

What do I need to do to get a new batch and invoice record started with SO_Shipping_BUS?

Here is my C# code:

   protected void RetCheck(object cmdResult, DispatchObject dispObj, ILogger Log = null) {

int res = (int)cmdResult;

if (res == 0) {

Exception e = new Exception(dispObj.LastErrorMessage);

if (Log != null) { Log.Error(e); }

throw e;

}

}

   

public void LoadInvoice(InvoiceSalesOrderHeader invoice, InvoiceSalesOrderHeader salesOrder)

{

ILogger Log = Logger.GetLogger();

SageInvoiceRecordId invoiceRecord = new SageInvoiceRecordId();

DateTime timestamp = DateTime.Now;

string dateString = timestamp.ToString("yyyyMMdd");

try

{

using (var pvx = new DispatchObject("ProvideX.Script"))

{

pvx.InvokeMethod("Init", Settings.SagePath);

using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")))

{

int userSuccess = (int)oSS.InvokeMethod("nSetUser", Settings.SageUser, Settings.SagePassword);

int companySuccess = (int)oSS.InvokeMethod("nSetCompany", Settings.SageCompany);

int moduleSuccess = (int)oSS.InvokeMethod("nSetModule", @"S/O");

int dateSuccess = (int)oSS.InvokeMethod("nSetDate", @"S/O", dateString);

int nTaskID = (int)oSS.InvokeMethod("nLookupTask", @"SO_" + Module + "_ui");

int nRetVal = (int)oSS.InvokeMethod("nSetProgram", nTaskID);

var sessionObj = oSS.GetObject();

using (var inHeader = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_Shipping_bus", sessionObj)))

{

// set up a batch for the invoice

string BatchNo = "";

object[] objs;

// Get a new Batch Number

string PrivateBatchFlag = "N";

string BatchCommentText = "Auto-Entry";

objs = new object[] { BatchNo, PrivateBatchFlag, BatchCommentText };

RetCheck(inHeader.InvokeMethodByRef("nSelectNewBatch", objs), inHeader, Log);

BatchNo = (string)objs[0];

// Batch Record in Database shows BatchSubType == "S" in GL_CompanyActiveBatch as desired from SO_Shipping_Bus

string InvoiceNo = "";

objs = new object[] { InvoiceNo };

RetCheck(inHeader.InvokeMethodByRef("nGetNextInvoiceNo", objs), inHeader, Log);

InvoiceNo = (string)objs[0];

RetCheck(inHeader.InvokeMethod("nSetKey", InvoiceNo), inHeader, Log);

// above line produces the error "Unable to select this batch. This batch was created in Invoice Data Entry."

// ... Do stuff with inHeader

// RetCheck(inHeader.InvokeMethod("nSetValue", "SalesOrderNo$", invoice.SalesOrderNo), inHeader, Log);

//  RetCheck(inHeader.InvokeMethod("nSetValue", "ShipperID$", "1"), inHeader, Log);

}

}

}

}

catch (Exception e2)

{

Log.Error(e2);

throw (e2);

}

}

  • 0
    SUGGESTED
    Ok. Here is the trick!!!

    Right after calling "nSelectNewBatch" and getting back BatchNo = (string) objs[0];

    one must call

    nSelectBatch and select this as the BatchNo.

    e.g.

    string PrivateBatchFlag = "N";
    string BatchCommentText = "Auto-Entry";
    object[] objs = new object[] { BatchNo, PrivateBatchFlag, BatchCommentText };
    RetCheck(inHeader.InvokeMethodByRef("nSelectNewBatch", objs), inHeader, Log);
    BatchNo = (string)objs[0];

    // One must do this next command to get the new BatchNo settings assigned to this SO_Shipping_bus object
    RetCheck(inHeader.InvokeMethod("nSelectBatch", BatchNo), inHeader, Log);