Create invoice using BOI

We are using sage 100 2019 and developing c# code for creating invoice in sage.i am able to create sales orders in sage with BOI but whenever i am creating invoice it is throwing error

{"Exception has been thrown by the target of an invocation."}

 

code  retVal = so_order.InvokeMethod("nAddLine");

  • Hard to tell with just that one line of code but it looks like you are calling the AddLine method from the SO_SalesOrder_Bus object instead of the SO_SalesOrderDetail_Bus object, which you should be able to get the handle to from the oLines property of the SO_SalesOrder_Bus object.

  • in reply to David Speck

    Thanks for reply.that error got fixed but now "Missing or invalid Header.

    complete code pasted here.

    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_Invoice_bus", oSS.GetObject())))
    {
    //string strSalesOrderNo = "";
    //object[] arrResults = new object[] { strSalesOrderNo };
    //retVal = so_order.InvokeMethodByRef("nGetNextSalesOrderNo", arrResults);
    //strSalesOrderNo = arrResults[0].ToString();
    // Add items to the header
    // successCheck((int) so_order.InvokeMethod("nSetKey", "1000"), "SetKey");
    // successCheck((int) so_order.InvokeMethod("nSetValue", "ARDivisionNo$", "00"), "SetValue");
    string error = (string) so_order.GetProperty("sLastErrorMsg");
    retVal = so_order.InvokeMethod("nSetValue", "SalesOrderNo$", "0000005");
    error = (string) so_order.GetProperty("sLastErrorMsg");
    //retVal = so_order.InvokeMethod("nSetValue", "VendorNo$", "0000100");
    error = (string) so_order.GetProperty("sLastErrorMsg");
    retVal = so_order.InvokeMethod("nSetValue", "InvoiceNo$", "0000005");
    error = (string) so_order.GetProperty("sLastErrorMsg");
    retVal = so_order.InvokeMethod("nSetValue", "InvoiceDate$", "20190312");
    retVal = so_order.InvokeMethod("nSetValue", "InvoiceDueDate$", "20190312");
    retVal = so_order.InvokeMethod("nSetValue", "InvoiceType$", "IN");
    retVal = so_order.InvokeMethod("nSetValue", "DiscountDueDate$", "20190312");

    retVal = so_order.InvokeMethod("nSetValue", "TaxSchedule$", "DEFAULT");
    //retval = (int) so_order.InvokeMethod("nFind", "0000005");
    //successCheck((int) so_order.InvokeMethod("nSetKey", "0000005"), "SetKey");
    retval = (int) so_order.InvokeMethod("nSetValue", "ARDivisionNo$", "00");
    retVal = so_order.InvokeMethod("nSetValue", "CustomerNo$", "0000100");
    //retVal = so_order.InvokeMethod("nSetValue", "TaxSchedule$", "DEFAULT");
    retVal = so_order.InvokeMethod("nSetValue", "TermsCode$", "00");
    //retVal = so_order.InvokeMethod("nSetValue", "OrderStatus$", "New");
    retVal = so_order.InvokeMethod("nSetValue", "OrderType$", "S");
    retVal = so_order.InvokeMethod("nSetValue", "OrderDate$", "20190312");
    retVal = so_order.InvokeMethod("nSetValue", "SalesPersonNo$", "0012");
    retVal = so_order.InvokeMethod("nSetValue", "PrintInvoice$", "N");
    error = (string) so_order.GetProperty("sLastErrorMsg");
    //bill to
    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");

    ////////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)
    {
    // Add a line
    retVal = so_order.InvokeMethod("nAddLine");
    error = (string) so_order.GetProperty("sLastErrorMsg");
    using (DispatchObject oLines = new DispatchObject(so_order.GetProperty("oLines")))
    {
    retVal = oLines.InvokeMethod("nAddLine");
    // retVal = oLines.InvokeMethodByRef("CopyLinesFromSalesOrder", "0000005");
    error = (string) oLines.GetProperty("sLastErrorMsg");
    retVal = oLines.InvokeMethod("nSetValue", "ItemCode$", "/1000");
    retVal = oLines.InvokeMethod("nSetValue", "ItemType$", "2");
    retVal = oLines.InvokeMethod("nSetValue", "UnitPrice$", 2);
    retVal = oLines.InvokeMethod("nSetValue", "Ordered$", 2);
    retVal = oLines.InvokeMethod("nSetValue", "SalesKitLineKey$", "320");
    retVal = oLines.InvokeMethod("nSetValue", "DistributionAmt$", 320);
    retVal = oLines.InvokeMethod("nSetValue", "TaxClass$", "NT");
    retVal = oLines.InvokeMethod("nWrite");
    //string error = (string) oLines.GetProperty("sLastErrorMsg");
    error = (string) oLines.GetProperty("sLastErrorMsg");

    }

    }
    //Write the order
    retVal = so_order.InvokeMethod("nWrite");

  • in reply to Viveknath

    I don't see anywhere in your code where you are actually setting the key for the invoice. Are you trying to hardcode the invoice number or do you want to use the next available invoice number?

    If the former, you need to call nSetKey and pass the hardcoded invoice number as the first argument.

    If the latter, then you need to use nGetNextInvoiceNo and pass a variable name into the first argument which will return the next available invoice number. You will then pass this variable in the first argument of the nSetKey method.