C# PO Write Fails BOI

SOLVED

First, thanks in advance for taking a look at this.  I'm looking at doing PO creation from C# and have been able to connect, get the next PO number etc., but everytime I try to finalize the PO, such as call the "nWrite" command, it always fails.  Any insight into what could be happening?  Below is my code.

using (DispatchObject poObject = new DispatchObject(pvx.InvokeMethod("NewObject", "PO_PurchaseOrder_bus", oSS.GetObject())))
{
try
{
string poNumber = "";
//int test1 = (int)poObject.InvokeMethod("nGetNextPurchaseOrderNo");
object[] poPass = new object[] {poNumber};
successCheck((int)poObject.InvokeMethodByRef("nGetNextPurchaseOrderNo", poPass), "GetNextPurchaseOrder");

//this was just to see what the PO number was coming back.
poNumber = poPass[0].ToString();

//we continue
successCheck((int) poObject.InvokeMethodByRef("nSetKey", poPass), "SetKey");
object[] divisionNoObject = new object[] {"APDivisionNo$", "00"};
successCheck((int) poObject.InvokeMethodByRef("nSetValue", divisionNoObject), "SetDivisionNo");
object[] vendorObject = new object[] { "VendorNo$", "0006630" };
successCheck((int)poObject.InvokeMethodByRef("nSetValue", vendorObject), "SetVendorNo");
object[] taxObject = new object[] { "TaxSchedule$", "NONTAX" };
successCheck((int)poObject.InvokeMethodByRef("nSetValue", taxObject), "SetTaxSchedule");

DispatchObject poLines = new DispatchObject(poObject.GetProperty("oLines"));
successCheck((int)poLines.InvokeMethod("nAddLine"), "AddLine");
object[] firstLine = new object[] { "ItemCode$", "/1." };
successCheck((int)poLines.InvokeMethodByRef("nSetValue", firstLine), "PoLineItemCode");
firstLine[0] = "QuantityOrdered";
firstLine[1] = "1";
successCheck((int)poLines.InvokeMethodByRef("nSetValue", firstLine), "PoLineQuantityOrdered");
successCheck((int)poLines.InvokeMethod("nWrite"), "PoLinesWrite");
successCheck((int) poObject.InvokeMethod("nWrite"), "Write");

MessageBox.Show("SUCCESS! " + poNumber.ToString());

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}

And below is my successCheck method to see what fails.

public void successCheck(int checkValue, string call)
{
if (checkValue == 0)
{
MessageBox.Show("Error! " + call);

}

}

Parents Reply Children
  • 0 in reply to BadgerJerry
    The item code is set to "/1." because of the way we work. We simply type in an item, not pull from an item code. This allows us to type in anything we want in the item field. Also, the syntax for the DispatchObject, which essentially is what allows for using C# in BOI, reads the "1" as a numeric 1 I believe. Just in case, I tested it by setting firstLine[1] = 1 and it ended up still failing at the same point. Good catches though. :)