Checking the sLastErrorMsg property is always a good idea! Luckily, if you are using the DispatchObject object wrapper that Sage provided, it includes a property indexer that makes it easy to do: var lastError = poObject["sLastErrorMsg"]; That said, I got your code to work in my test project pretty much as is... I fixed the nSetKey line to pass the string poNumber, vs. the object array named poPass. The other thing I changed was the usage of InvokeMethodByRef to InvokeMethod, in a few places, where parameters are passed by value, not by ref. Not sure if this caused any problem, but ByRef is more overhead so I only use it when needed. Also I changed the vendor to 01-AIRWAY and the item code to "6655" to work with my ABX company, but everything else should fly. Thanks! Bret. 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.InvokeMethod("nSetKey", poNumber) , "SetKey"); object[] divisionNoObject = new object[] { "APDivisionNo$", "01" }; successCheck((int)poObject.InvokeMethod("nSetValue", divisionNoObject), "SetDivisionNo"); object[] vendorObject = new object[] { "VendorNo$", "AIRWAY" }; successCheck((int)poObject.InvokeMethod("nSetValue", vendorObject), "SetVendorNo"); object[] taxObject = new object[] { "TaxSchedule$", "NONTAX" }; successCheck((int)poObject.InvokeMethod("nSetValue", taxObject), "SetTaxSchedule"); DispatchObject poLines = new DispatchObject(poObject.GetProperty("oLines")); successCheck((int)poLines.InvokeMethod("nAddLine"), "AddLine"); //object[] firstLine = new object[] { "ItemCode$", "/1." }; object[] firstLine = new object[] { "ItemCode$", "6655" }; successCheck((int)poLines.InvokeMethod("nSetValue", firstLine), "PoLineItemCode"); firstLine[0] = "QuantityOrdered"; firstLine[1] = "1"; successCheck((int)poLines.InvokeMethod("nSetValue", firstLine), "PoLineQuantityOrdered"); successCheck((int)poLines.InvokeMethod("nWrite"), "PoLinesWrite"); successCheck((int)poObject.InvokeMethod("nWrite"), "Write"); Console.WriteLine("SUCCESS! " + poNumber.ToString());
↧