📚 SAP Business One SDK Help

Invoice Document - Add Method Sample
See Also

Description

The following sample shows how to add an invoice (with lines) document to the database. Use this sample as a basis to all business objects of document type (not master data type).
 Sub AddInvoice_Click()
    Dim RetVal As Long
    Dim ErrCode As Long
    Dim ErrMsg As String
    'Create the Documents object
    Dim vInvoice As SAPbobsCOM.Documents
    Set vInvoice = vCmp.GetBusinessObject(oInvoices)
    'Set values to the fields
    vInvoice.Series = 0
    vInvoice.CardCode = "BP234"
    vInvoice.HandWritten = tNO
    vInvoice.PaymentGroupCode = "-1"
    vInvoice.DocDate = "21/8/2003"
    vInvoice.DocTotal = 264.6

    'Invoice Lines - Set values to the first line
    vInvoice.Lines.ItemCode = "A00023"
    vInvoice.Lines.ItemDescription = "Banana"
    vInvoice.Lines.PriceAfterVAT = 2.36
    vInvoice.Lines.Quantity = 50
    vInvoice.Lines.Currency = "Eur"
    vInvoice.Lines.DiscountPercent = 10

    'Invoice Lines - Set values to the second line
    vInvoice.Lines.Add
    vInvoice.Lines.ItemCode = " A00033"
    vInvoice.Lines.ItemDescription = "Orange"
    vInvoice.Lines.PriceAfterVAT = 118
    vInvoice.Lines.Quantity = 1
    vInvoice.Lines.Currency = "Eur"
    vInvoice.Lines.DiscountPercent = 10

    'Add the Invoice
    RetVal = vInvoice.Add

   'Check the result
    If RetVal <> 0 Then
        vCmp.GetLastError ErrCode, ErrMsg
        MsgBox ErrCode & " " & ErrMsg
    End If
 End Sub