cancel
Showing results for 
Search instead for 
Did you mean: 

"Invalid Index -1105" when adding AR Invoice using SDK

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

I have commented the line oInv.Lines.Add() but am still getting invalid index -1105.

Former Member
0 Kudos

Its working now, i had tried the code on another database.

I just wanted to know what is "Invalid Index -1105" .

Thx

Former Member
0 Kudos

If on another db it works, I think that in non working db is missing some datas you äre setting to invoice as BP code, VAT code, itemcode, .. Check it.

Former Member
0 Kudos

thx

Former Member
0 Kudos

I'm getting the same error message when adding an Item.

Error Message: (8)

Error Number: -1105

Any ideas?

Former Member
0 Kudos

Further more, executing the sample code provided my SAP returns the same error

vItem.ItemCode = "MyNewItem"

'Set Value to other fields

vItem.ItemName = "MyNewItem Name"

vItem.WhsInfo.WarehouseCode = "01"

'Adding the Item

RetVal = vItem.Add

Error Message: (8)

Error Number: -1105

Answers (3)

Answers (3)

Former Member
0 Kudos

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

Former Member
0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

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.