Skip to Content
avatar image
Former Member

Create a delivery via DI API from a Sales Order

I am programmatically creating a delivery upon successful shipment of an order. When the delivery is created, I get Quantity falls into negative inventory [DLN1.ItemCode][line: 1] for a product with positive inventory.

The delivery is created from the sales order once the order has been confirmed shipped. Lastly, this is SAP B1 9.1 HANA.

Thanks.

Keith

   Private Function createDelivery(SalesOrderKey As Integer, MyConn As OdbcConnection)
        Dim myString As String = ""
        Dim ivar As Integer
        Dim icnt As Integer
        Dim oSalesOrder As SAPbobsCOM.Documents
        Dim oDeliveryNote As SAPbobsCOM.Documents
        Dim oDeliveryLines As SAPbobsCOM.Documents
        Dim lRetCode As Integer
        Dim PostSuccess As Boolean
        Dim DeliveryLineAdded As Boolean
        oSalesOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
        If oSalesOrder.GetByKey(SalesOrderKey) Then
            oDeliveryNote = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
            oDeliveryNote.CardCode = oSalesOrder.CardCode
            oDeliveryNote.SalesPersonCode = oSalesOrder.SalesPersonCode
            oDeliveryNote.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items
            oDeliveryNote.DocumentSubType = SAPbobsCOM.BoDocumentSubType.bod_None
            oDeliveryNote.Address = oSalesOrder.Address
            oDeliveryNote.ShipToCode = oSalesOrder.ShipToCode
            oDeliveryNote.Address2 = oSalesOrder.Address2
            oDeliveryNote.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
            oDeliveryNote.JournalMemo = "Delivery - " & oSalesOrder.CardCode
            oDeliveryNote.Comments = "Based on SO " & Convert.ToString(SalesOrderKey)
            oDeliveryNote.PaymentGroupCode = oSalesOrder.PaymentGroupCode
            oDeliveryNote.DocObjectCode = SAPbobsCOM.BoObjectTypes.oDeliveryNotes
            oDeliveryNote.DocObjectCodeEx = SAPbobsCOM.BoObjectTypes.oDeliveryNotes
            oDeliveryNote.DocDueDate = Now.Month & "/" & Now.Day & "/" & Now.Year
            oDeliveryNote.TrackingNumber = ""
            
            For icnt = 0 To oSalesOrder.Lines.Count - 1
                oSalesOrder.Lines.SetCurrentLine(icnt)
                oDeliveryNote.Lines.ItemCode = oSalesOrder.Lines.ItemCode
                oDeliveryNote.Lines.Quantity = oSalesOrder.Lines.Quantity


                UpdateSystemLog(0, 0, "Insert Delivery SKU: " + oSalesOrder.Lines.ItemCode, "IME-D0V", MyConn)
                UpdateSystemLog(0, 0, "Insert Delivery Quantity: " + Convert.ToString(oSalesOrder.Lines.Quantity), "IME-D0V", MyConn)


                oDeliveryNote.Lines.DiscountPercent = oSalesOrder.Lines.DiscountPercent
                oDeliveryNote.Lines.TaxCode = oSalesOrder.Lines.TaxCode
                oDeliveryNote.Lines.LineTotal = oSalesOrder.Lines.LineTotal
                oDeliveryNote.Lines.COGSCostingCode = oSalesOrder.Lines.COGSCostingCode
                oDeliveryNote.Lines.COGSCostingCode2 = oSalesOrder.Lines.COGSCostingCode2
                oDeliveryNote.Lines.COGSCostingCode3 = oSalesOrder.Lines.COGSCostingCode3
                oDeliveryNote.Lines.COGSCostingCode4 = oSalesOrder.Lines.COGSCostingCode4
                oDeliveryNote.Lines.COGSCostingCode5 = oSalesOrder.Lines.COGSCostingCode5
                oDeliveryNote.Lines.Rate = oSalesOrder.Lines.Rate

                oDeliveryNote.Lines.Add()
            Next
            lRetCode = oDeliveryNote.Add()

            If lRetCode <> 0 Then
                Dim sErr As String
                oCompany.GetLastError(lRetCode, sErr)
                UpdateSystemLog(lRetCode, 0, "Insert Delivery Error --> " + sErr, "IME-D0A", MyConn)
            Else
                Dim sErr As String
                oCompany.GetLastError(lRetCode, sErr)
                UpdateSystemLog(lRetCode, 0, "Insert Delivery --> " + sErr, "IME-D0B", MyConn)
            End If


        End If
    End Function
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers