Hello all,
I have some code in which I am trying to check the "on water" status of a PO line (via an Excel file from the factory) and adjust the PO line item accordingly. Basically, if the amount on the water is < the original PO amount, then I want to:
(a) Edit the existing open PO line item to reflect the quantity shipped, and
(b) Add a new PO line item to hold the "back order" quantity.
I am using the DI-API to do this, but it doesn't seem to be working, even though the GetByKey method is returning a PO document object. Here is my code below. Can anyone help elaborate as to why my existing PO line item quantity is not changed, nor is the system adding the new line item. Is it possible to do this via the DI-API and the Document object?
docPO = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders);
if(docPO.GetByKey(System.Convert.ToInt32(ss.docEntry)))
{
// Add a new PO line that makes up the difference in what was shipped and the original quantity
docPO.Lines.ItemCode = ssi.itemCode;
docPO.Lines.Quantity = System.Convert.ToDouble(poLineRow["OpenQty"].ToString()) - draft.Lines.Quantity;
docPO.Lines.WarehouseCode = ssi.whsCode;
docPO.Lines.Price = ssi.price;
docPO.Lines.Add();
// Now modify the existing, "original" PO line item to reflect the quantity change (this will show what actually shipped)
docPO.Lines.SetCurrentLine(System.Convert.ToInt32(poLineRow["LineNum"].ToString()));
docPO.Lines.Quantity = draft.Lines.Quantity;
result = docPO.Update();
if(result != 0)
{
emailSupport("An SAP error at draft.Add() for Purchase Document " + tempDocEntry + "\n\n" + company.GetLastErrorDescription(), tempCardCode);
return;
}
}
My result returns 0 which would seem to indicate success, but this is not the case. Can anyone help or offer any advice?
Thanks,
Jonathan