SAP Business One DI API StockTransfer Object Error -1116

1.8k views Asked by At

i'm trying to insert Inventory Transfer using SBO DI API (v9), but every time its executed always failed and return error code

-1116 Internal error (-5002) occurred

If we change

oDoc = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);

into

oDoc = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransferDraft);

the document was saved but as an Inventory Transfer DRAFT, so we need to open SAP GUI to open the draft then add it manually to post as Inventory Transfer Document, this is not what I want to do. I think there are some mandatory fields that I'm missing or DI API not supported to post Inventory Transfer document?, the problem is I don't know how to trace them, the error message is not helpful at all. FYI, I have created some API like PickList, Inventory Transfer Request but there is no problem at all.

here's my code for your reference:

        SAPConnection connection = new SAPConnection();
        SAPbobsCOM.Company company = connection.OpenConnection();

        if (company != null) {
            SAPbobsCOM.IStockTransfer oDoc;
            oDoc = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
            
            //HEADER DEFINITION
            oDoc.Series = 347;  //SERIES NUMBER
            oDoc.FromWarehouse = d["h"]["FROM"].ToString();
            oDoc.ToWarehouse = d["h"]["TO"].ToString();
            oDoc.Comments = "Generated Automatically From WMS [" + d["h"]["NUMBER"].ToString() + "]";
            oDoc.JournalMemo = "Inventory Transfer - WMS";
            oDoc.DocDate = DateTime.Today;
            oDoc.DueDate = DateTime.Today;
            oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oStockTransfer;

            //DETAIL DEFINITION
            Int16 lines = (short)d["d"].Count();
            
            for(int i = 0; i<lines; i++) {
                if (i > 0)
                {
                    oDoc.Lines.Add();
                }

                oDoc.Lines.BaseType = SAPbobsCOM.InvBaseDocTypeEnum.InventoryTransferRequest;
                oDoc.Lines.BaseEntry = Convert.ToInt32(d["h"]["ID"].ToString());   //ID ITR
                oDoc.Lines.BaseLine = i;
                
                oDoc.Lines.ItemCode = d["d"][i]["item_no"].ToString();
                oDoc.Lines.ItemDescription = d["d"][i]["item_description"].ToString();
                oDoc.Lines.WarehouseCode = d["h"]["TO"].ToString();
                oDoc.Lines.FromWarehouseCode = d["h"]["FROM"].ToString();
                oDoc.Lines.Quantity = Convert.ToDouble(d["d"][i]["qty"].ToString());

                oDoc.Lines.BatchNumbers.BatchNumber = d["d"][i]["batch"].ToString();
                oDoc.Lines.BatchNumbers.Quantity = Convert.ToDouble(d["d"][i]["qty"].ToString());
            }

            int status = oDoc.Add();

            if (status == 0)
            {
                callResponse.Code = "OK";
                callResponse.Description = "Success #" + company.GetNewObjectKey();
            }
            else
            {
                callResponse.Code = "ERROR";
                callResponse.Description = company.GetLastErrorCode().ToString() + " " + company.GetLastErrorDescription().ToString();
            };


            return Ok(callResponse);
        }

        callResponse.Code = "ERROR";
        callResponse.Description = "Failed to connect server ! ";
        return Ok(callResponse);
1

There are 1 answers

1
Oscar Valladares On

Try

oDocumento = null;
oDocumento = Documents)SAPB1.myCompany.GetBusinessObject(BoObjectTypes.oDrafts);
oDocumento.DocObjectCode = BoObjectTypes.oStockTransfer;