how to set shipping Qunatity in shipping data entry?

I have done following code to create shipping entry in sage using business object.But After Execute code I am able to get to get item in lines but i am always getting shipped quantity value zero.

using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))
{
pvx.InvokeMethod("Init", sagePath);
using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")))
{
//oSS.InvokeMethod("nLogon");
oSS.InvokeMethod("nSetCompany", sageOrganization);
oSS.InvokeMethod("nSetUser", 1, "roy");
oSS.InvokeMethod("nSetDate", "S/O", DateTime.Now.ToString("yyyyMMdd"));
oSS.InvokeMethod("nSetModule", "S/O");

// Get the Task ID for the AR_Customer_ui program
int taskID = (int)oSS.InvokeMethod("nLookupTask", "SO_Shipping_UI");
oSS.InvokeMethod("nSetProgram", taskID);

using (DispatchObject oSalesOrderEntry = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_Shipping_bus", oSS.GetObject())))
{
try
{
object[] nextOrderNum = new object[] { "InvoiceNo$" };
oSalesOrderEntry.InvokeMethodByRef("nGetNextInvoiceNo", nextOrderNum);
oSalesOrderEntry.InvokeMethod("nSetKey", nextOrderNum[0]);
oSalesOrderEntry.InvokeMethod("nSetValue", "CustomerNo$", "C105");
oSalesOrderEntry.InvokeMethod("nSetValue", "ShipperID$", "1");
oSalesOrderEntry.InvokeMethod("nSetValue", "ShipStatus$", "L");
oSalesOrderEntry.InvokeMethod("nSetValue", "InvoiceDate$", DateTime.Now.ToString("yyyyMMdd"));
//oSalesOrderEntry.InvokeMethod("nSetValue", "OrderType$", "S");
//oSalesOrderEntry.InvokeMethod("nSetValue", "OrderStatus$", "N");
oSalesOrderEntry.InvokeMethod("nSetValue", "SalespersonNo$", "S145");
oSalesOrderEntry.InvokeMethod("nSetValue", "TaxSchedule$", "CA LA");
oSalesOrderEntry.InvokeMethod("nSetValue", "SalesOrderNo$", "S149");
//oSalesOrderEntry.InvokeMethod("nSetValue", "LotSerialLinesExist$", "Y");

//oSalesOrderEntry.InvokeMethod("nSetValue", "LotSerialLinesExist$", "Y");
// oSalesOrderEntry.InvokeMethod("nAddLine");
oSalesOrderEntry.InvokeMethod("nWrite");

DispatchObject sales_order_line = new DispatchObject(oSalesOrderEntry.GetProperty("oLines"));

//sales_order_lin("WarehouseCode$","000")
// sales_order_line.InvokeMethod("nSetValue", "ItemCode$", "TEST2");
// sales_order_line.InvokeMethod("nSetValue", "WarehouseCode$", "000");
// sales_order_line.InvokeMethod("nSetValue", "ItemType", 1);
//sales_order_line.InvokeMethod("nSetValue", "QuantityOrdered", "1");
//sales_order_line.InvokeMethod("nSetValue", "QuantityOrdered", 2);
sales_order_line.InvokeMethod("nSetValue", "QuantityShipped", 2);
sales_order_line.InvokeMethod("nWrite");


//sales_order_line.InvokeMethod("nSetValue", "LotSerialFullyDistributed$", "Y");


//DispatchObject sales_order_Distribution = new DispatchObject(sales_order_line.GetProperty("oDistribution"));

//sales_order_Distribution.InvokeMethod("nAddDistributionLine", "S1-107");
//sales_order_Distribution.InvokeMethod("nSetValue", "QuantityShipped", 1);
//// sales_order_Distribution.InvokeMethod("nSetKeyValue", "InvoiceNo$", nextOrderNum[0]);
//// sales_order_Distribution.InvokeMethod("SetKeyValue", "LotSerialNo$", "S1-102");
//// sales_order_Distribution.InvokeMethod("SetValue", "QuantityShipped$", "1");
//sales_order_Distribution.InvokeMethod("nWrite");//string filter = string.Empty;


//char QUO = Convert.ToChar(34);
//string ItemCostRecIOL = "LotSerialNo$+" + QUO + "|" + QUO +
// "+InvoiceNo$+" + QUO + "|" + QUO +
// "+LineKey$";
//object[] getResultSetParams = new object[] { "InvoiceNo$", "STR(LotSerialLinesExist)", "ItemCodeDesc$", "", filter, "", "" };
//object retval = oSalesOrderEntry.InvokeMethodByRef("nGetResultSets", getResultSetParams);
//string[] strSalesOrders = getResultSetParams[2].ToString().Split(System.Convert.ToChar(352));
}
catch (Exception ex)
{
}
}
}
}

  • 0
    You're should perform the write to the shipment object after you perform the write to the lines.
  • 0 in reply to BadgerJerry
    i have used code in following way

    object[] nextOrderNum = new object[] { "InvoiceNo$" };
    oSalesOrderEntry.InvokeMethodByRef("nGetNextInvoiceNo", nextOrderNum);
    oSalesOrderEntry.InvokeMethod("nSetKey", nextOrderNum[0]);
    oSalesOrderEntry.InvokeMethod("nSetValue", "CustomerNo$", "C105");
    oSalesOrderEntry.InvokeMethod("nSetValue", "ShipperID$", "1");
    oSalesOrderEntry.InvokeMethod("nSetValue", "ShipStatus$", "L");
    oSalesOrderEntry.InvokeMethod("nSetValue", "InvoiceDate$", DateTime.Now.ToString("yyyyMMdd"));
    //oSalesOrderEntry.InvokeMethod("nSetValue", "OrderType$", "S");
    //oSalesOrderEntry.InvokeMethod("nSetValue", "OrderStatus$", "N");
    oSalesOrderEntry.InvokeMethod("nSetValue", "SalespersonNo$", "S145");
    oSalesOrderEntry.InvokeMethod("nSetValue", "TaxSchedule$", "CA LA");
    oSalesOrderEntry.InvokeMethod("nSetValue", "SalesOrderNo$", "S149");
    //oSalesOrderEntry.InvokeMethod("nSetValue", "LotSerialLinesExist$", "Y");

    //oSalesOrderEntry.InvokeMethod("nSetValue", "LotSerialLinesExist$", "Y");
    oSalesOrderEntry.InvokeMethod("nAddLine");


    DispatchObject sales_order_line = new DispatchObject(oSalesOrderEntry.GetProperty("oLines"));

    //sales_order_lin("WarehouseCode$","000")
    sales_order_line.InvokeMethod("nSetValue", "ItemCode$", "TEST2");
    sales_order_line.InvokeMethod("nSetValue", "WarehouseCode$", "000");
    sales_order_line.InvokeMethod("nSetValue", "ItemType", 1);
    sales_order_line.InvokeMethod("nSetValue", "QuantityOrdered", "1");
    sales_order_line.InvokeMethod("nSetValue", "QuantityOrdered", 2);
    sales_order_line.InvokeMethod("nSetValue", "QuantityShipped", 2);
    sales_order_line.InvokeMethod("nWrite");


    oSalesOrderEntry.InvokeMethod("nWrite");

    which lead me to result where
    www.dropbox.com/.../issue.png

    it create new entry and old entry for line have 0 shipping quantity
  • 0 in reply to royn
    Instead of using nAddLine which adds a new line, you should use nMoveFirst/nMoveNext to find the item in the invoice you want to update. I don't remember if all lines are automatically copied over when you set SalesOrderNo. If they are not, then you need to do this first:

    sales_order_line.InvokeMethod("nCopyLinesFromSalesOrder", "S149", "YES");

    The first argument is sales order number. The second argument is ship complete ("YES" or "NO"). For shipping invoice, you need to pass in YES to make sure quantity backordered will be calculated correctly. It won't really ship complete.
  • 0 in reply to Natasha Chang
    Is there sample code for nMoveFirst/nMoveNext using DispatchObject?
  • 0 in reply to royn
    I need to do this because I also want to add distribution to each line
  • 0 in reply to Natasha Chang
    AS per I think line automatically copied.We need to get lines and iterate and need to update shipped quantity.
  • 0 in reply to royn
    I probably got the syntax wrong but you should get the idea:

    sales_order_line.InvokeMethod("nMoveFirst");
    while not(sales_order_line.nEOF)
    {
    sales_order_line.InvokeMethod("nGetValue", "ItemCode$", itemcode);
    // check item code and do what you need to do with the line, remember to write the line
    sales_order_line.InvokeMethod("nMoveNext");
    }
  • 0 in reply to Natasha Chang
    thanks all for help.I am able to do this.