I'm getting this error if I leave off the sales order number. I want to be able to enter the sales order invoice without a preexisting sales order. All the code seems to work and the data is being input into Sage, however the tax fields never populate (sales tax amount, invoice total etc.) in the Totals tab. Do I have to create the sales order first, and then the invoice in order to get the tax info? What am I missing?
Complete Code.
using (DispatchObject so_order = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_Invoice_bus", oSS.GetObject()))) { //Get next invoice Number string strInvoicerNo = ""; object[] arrResults = new object[] { strInvoicerNo }; retVal = so_order.InvokeMethodByRef("nGetNextInvoiceNo", arrResults); strInvoicerNo = arrResults[0].ToString(); //Add new Batch No string strBatchNo = ""; object[] arr1Results = new object[] { "BBBAA" }; //retVal = so_order.InvokeMethodByRef("nSelectBatch", arr1Results); successCheck((int)so_order.InvokeMethod("nSelectBatch", arr1Results), "Write"); strBatchNo = arr1Results[0].ToString(); successCheck((int)so_order.InvokeMethod("nSetValue", "BATCHNO$", strBatchNo), "SetBatchNo"); string error = (string)so_order.GetProperty("sLastErrorMsg"); ERROR HERE * // Setting this off throws the error, missing record to calculate taxes // retVal = so_order.InvokeMethod("nSetValue", "SalesOrderNo$", "000030"); retVal = so_order.InvokeMethod("nSetValue", "InvoiceType$", "IN"); retVal = so_order.InvokeMethod("nSetValue", "TaxSchedule$", "CA OR"); error = (string)so_order.GetProperty("sLastErrorMsg"); retVal = so_order.InvokeMethod("nSetKey", strInvoicerNo); retVal = so_order.InvokeMethod("nSetValue", "ARDivisionNo$", "01"); retVal = so_order.InvokeMethod("nSetValue", "CustomerNo$", "ALLTECH"); retVal = so_order.InvokeMethod("nSetValue", "TermsCode$", "01"); retVal = so_order.InvokeMethod("nSetValue", "SalesPersonNo$", "0300"); error = (string)so_order.GetProperty("sLastErrorMsg"); retVal = so_order.InvokeMethod("nSetValue", "InvoiceDate$", accDate); { error = so_order.InvokeMethod("sGetColumns", "MAIN").ToString().Replace(System.Convert.ToChar(352), '\n'); error = (string)so_order.GetProperty("sLastErrorMsg"); using (DispatchObject oLines = new DispatchObject(so_order.GetProperty("oLines"))) { retVal = oLines.InvokeMethod("nAddLine"); retVal = oLines.InvokeMethod("nGetValue", "QUANTITYSHIPPED", 2); error = (string)so_order.GetProperty("sLastErrorMsg"); retVal = oLines.InvokeMethod("nSetValue", "ItemCode$", "MICRO-00122"); retVal = oLines.InvokeMethod("nSetValue", "QUANTITYORDERED", 5); retVal = oLines.InvokeMethod("nSetValue", "QUANTITYSHIPPED", 2); error = (string)oLines.GetProperty("sLastErrorMsg"); retVal = oLines.InvokeMethod("nSetValue", "SalesKitLineKey$", "320"); //retVal = oLines.InvokeMethod("nSetValue", "DistributionAmt$", 320); retVal = oLines.InvokeMethod("nSetValue", "TaxClass$", "NT"); successCheck((int)oLines.InvokeMethod("nWrite"), "Write"); error = (string)oLines.GetProperty("sLastErrorMsg"); //error = (string) oLines.GetProperty("sLastErrorMsg"); error = oLines.InvokeMethod("sGetColumns", "MAIN").ToString().Replace(System.Convert.ToChar(352), '\n'); } } //Write the order retVal = so_order.InvokeMethod("nWrite");