SO invoicing Error :"Missing or Invalid Header"

Hello

I am writing script to create invoice using BOI,but it gives error when writing Line items "Missing or Invalid Header".Can someone help on this.

My code snippet

int TaskID = (int) oSS.InvokeMethod("nLookupTask", "SO_Invoice_Ui");
oSS.InvokeMethod("nSetProgram", TaskID);

int retval = 0;

// using (DispatchObject so_order = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", oSS.GetObject())))
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[] { "5" };
retVal = so_order.InvokeMethodByRef("nSelectBatch", arr1Results);
strBatchNo = arr1Results[0].ToString();


//retVal = so_order.InvokeMethod("nSetValue", "BATCHNO$", strBatchNo);

string error = (string) so_order.GetProperty("sLastErrorMsg");
retVal = so_order.InvokeMethod("nSetValue", "SalesOrderNo$", "0000005");
retVal = so_order.InvokeMethod("nSetValue", "InvoiceType$", "IN");
retVal = so_order.InvokeMethod("nSetValue", "TaxSchedule$", "DEFAULT");



error = (string) so_order.GetProperty("sLastErrorMsg");
retVal = so_order.InvokeMethod("nSetValue", "InvoiceNo$", strInvoicerNo);

retVal = so_order.InvokeMethod("nSetValue", "CustomerNo$", "0000100");

retVal = so_order.InvokeMethod("nSetValue", "TermsCode$", "00");
retVal = so_order.InvokeMethod("nSetValue", "SalesPersonNo$", "0012");

//bill to
error = (string) so_order.GetProperty("sLastErrorMsg");
// retVal = so_order.InvokeMethod("nSetValue", "BillToCustomerNo$", "0000101");
//error = (string) so_order.GetProperty("sLastErrorMsg");
//retVal = so_order.InvokeMethod("nSetValue", "BillToName$", "VIVEK");
//retVal = so_order.InvokeMethod("nSetValue", "BillToAddress1$", "");
//retVal = so_order.InvokeMethod("nSetValue", "BillToCity$", "PLANO");
//retVal = so_order.InvokeMethod("nSetValue", "BillToState$", "TX");
//retVal = so_order.InvokeMethod("nSetValue", "BillToZipCode$", "75024");
//retVal = so_order.InvokeMethod("nSetValue", "BillToCountryCode$", "USA");
//retVal = so_order.InvokeMethod("nSetValue", "SHIPPERID$","12");
// retVal = so_order.InvokeMethod("nSetValue", "NONTAXABLEAMT", 0.0);
////retVal = so_order.InvokeMethod("nSetValue", "SALESTAXAMT", 0.00);
//retVal = so_order.InvokeMethod("nSetValue", "DISCOUNTAMT", 0.0);
error = (string) so_order.GetProperty("sLastErrorMsg");

////////Shipto
//retVal = so_order.InvokeMethod("nSetValue", "ShipToName$", "VIVEK");
//retVal = so_order.InvokeMethod("nSetValue", "ShipToAddress1$", "");
//retVal = so_order.InvokeMethod("nSetValue", "ShipToCity$", "PLANO");
//retVal = so_order.InvokeMethod("nSetValue", "ShipToState$", "TX");
//retVal = so_order.InvokeMethod("nSetValue", "ShipToZipCode$", "75024");
//retVal = so_order.InvokeMethod("nSetValue", "ShipToCountryCode$", "USA");
//// foreach (var line in salesOrderModel.Items)
retVal = so_order.InvokeMethod("nSetValue", "InvoiceDate$", "20190512");
{
// Add a line
retVal = so_order.InvokeMethod("nAddLine");//Getting error here

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 = so_order.InvokeMethod("nApplySalesOrderCopyLines", 1);
error = (string) so_order.GetProperty("sLastErrorMsg");
retVal = oLines.InvokeMethod("nSetValue", "ItemCode$", "/1000");
//retVal = oLines.InvokeMethod("nSetValue", "ItemType$", "2");
retVal = oLines.InvokeMethod("nSetValue", "QUANTITYORDERED", 2);
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");
retVal = oLines.InvokeMethod("nWrite");
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");

Parents Reply Children