on 09-10-2008 6:35 AM
Hi,
I am trying to add an A/R Invoice using SDK by using the OInvoice object but when adding the invoice its generating an error "Invalid Index -1105"
Here the code am using:
Private Sub AddOrderToDatabase()
Dim iError, iCount As Integer
Dim sErrMsg As String
Dim oInv As SAPbobsCOM.Documents
oInv = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
Dim oBob As SAPbobsCOM.SBObob
oInv.CardCode = "ACC001-C"
oInv.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
oInv.DocDate = "#9/9/2008#"
oInv.DocDueDate = "#9/9/2008#"
oInv.DocCurrency = "USD"
oInv.Lines.ItemCode = "test001"
oInv.Lines.ItemDescription = "test"
oInv.Lines.Quantity = 1
oInv.Lines.UnitPrice = 10
oInv.Lines.VatGroup = "O1"
oInv.Lines.Add()
lretcode = oInv.Add
If lretcode <> 0 Then
oCompany.GetLastError(iError, sErrMsg)
MessageBox.Show(iError & " " & sErrMsg, "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("imported successfully.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Dear PRADHA LUCHUN,
Please remove the code line
oInv.Lines.Add()
The document object has a default line and you don't need to call Lines.Add() if the document has one line.
Best Regards
Jane Jing
SAP Business One Forums team
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
this is the code i used to add an item using SDK and it works perfectly.Hope it helps you.
Private Sub addOITM()
Dim oitems As SAPbobsCOM.Items
oitems = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
oitems.ItemCode = itemCode
oitems.ItemName = Mid(itemName, 1, 100)
oitems.UserFields.Fields.Item("U_ItemSubgroup").Value = itemsubgrp
oitems.ItemsGroupCode = 108
oitems.ManageBatchNumbers = SAPbobsCOM.BoYesNoEnum.tYES
oitems.Add()
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
this is the code verbatim from my solution:
SAPbobsCOM.Items oItems = (SAPbobsCOM.Items)sapCompany.GetBusinessObject(BoObjectTypes.oItems);
oItems.ItemCode = "abc123";
oItems.ItemName = "MyNewItem Name";
if (oItems.Add() != 0)
sapCompany.GetLastError(out error, out errormessage);
Can you spot any potential problems in the snippet above?
Hi,
For a single entry of line item u not need to add
oInv.Lines.Add().u directly give the lretcode = oInv.Add.
For multiple of line items u have to give oInv.line.Add().For adding the last record u need not to give the line oInv.line.Add().otherwise
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).
Source 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
i hope this will help u........:)
Regards
Mohana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oInv.Lines.Add()
is not necessary, because first row exists already. Try it without this or have a look in sdk samples, where is creting of invoice explained with code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.