📚 SAP Business One SDK Help

Add Method
See Also  Example

Description

Adds a record to the object table in SAP Business One company database.

Syntax

Visual Basic
Public Function Add() As Long

Return Type

Returns a result value that indicates success or failure. If the method succeeds, it returns 0. Otherwise, it returns an error code.

You can retrieve the last error code and its description using the method GetLastError.

Remarks

You must values for the mandatory properties, and then call the Add method. The auto-complete feature completes all the default values of the other properties. In the DI API, the auto-complete feature operates the same way as in the SAP Business One application.

Example

The following sample shows how to add an invoice (with lines) document to the database. Use this sample as a basis for all business objects of document type (not master data type).
Invoice Document - Add Method Sample (Visual Basic)Copy Code
 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

See Also