cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot Add a new Accounting Entries - SDK

Former Member
0 Kudos
91

Dear Sir,

I need to add an accounting entry into SAP BO via SDK.

I am using the following code:

For iColCount = 1 To lFactorColl.Count

'//Search Accounting information

oTable = oDataSet.Tables("DocList")

Dim oSRows() As DataRow = oTable.Select("FactorCode = '" & lFactorColl.Item(iColCount).ToString & "'")

oJE = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)

Try

iIndex = 0

oJE.TaxDate = CDate(Right(oDate, 2) & "/" & Mid(oDate, 5, 2) & "/" & Left(oDate, 4))

oJE.DueDate = CDate(Right(oDate, 2) & "/" & Mid(oDate, 5, 2) & "/" & Left(oDate, 4))

oJE.ReferenceDate = CDate(Right(oDate, 2) & "/" & Mid(oDate, 5, 2) & "/" & Left(oDate, 4))

oJE.Memo = "test"

'// Set the first lines for the clients invoices - credit side

For iRowCount = 0 To oSRows.GetUpperBound(0)

iIndex = iRowCount

oJE.Lines.SetCurrentLine(iIndex)

'sAccountKey = GetAccountKey(oSRows(iRowCount)("CardCode"))

oJE.Lines.ShortName = oSRows(iRowCount)("CardCode")

'oJE.Lines.AccountCode = oSRows(iRowCount)("CardCode")

'sAccountKey = GetAccountKey(oSRows(iRowCount)("FactorCode"))

'oJE.Lines.ContraAccount = sAccountKey

sFactor = lFactorColl.Item(iColCount + 1).ToString

oJE.Lines.Credit = CDbl(Replace(oSRows(iRowCount)("Amount"), ".", ","))

sTotalAmt = sTotalAmt + CDbl(Replace(oSRows(iRowCount)("Amount"), ".", ","))

oJE.Lines.Add()

Next iRowCount

'Set the factor line - debit side

iIndex = iIndex + 1

oJE.Lines.SetCurrentLine(iIndex)

'sAccountKey = GetAccountKey(sFactor)

'oJE.Lines.AccountCode = sFactor

oJE.Lines.ShortName = "02"

oJE.Lines.Debit = sTotalAmt

oJE.Lines.Add()

If oJE.Add = 0 Then

Dim num As Integer

oCompany.GetLastError(num, sStr2)

SBO_Application.MessageBox(sStr2)

Else

SBO_Application.MessageBox("Import was successful!")

oJE.SaveXML("c:\JournalEntries" + Str(oJE.Number) + ".xml")

End If

Catch exception1 As Exception

End Try

Next

this code does not generate any error but no accouting entry are entered although if i try to enter it manually, it is saved in the database.

please advise what it is wrong in my code making it not working properly.

PS: both credit and Debit side in my entry is using the BP code and not G/L account.

Best Regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

There are a couple of things that I noticed, if I'm reading your code right. First, it appears you are

issuing the oJE.Lines.Add() command at the end of your loop (which would be in preparation for filling that line with data after reading the next row back at the top of the loop). If that's the case then when you fill your last good line item with data, you're going to add a blank line into the object, and I think that would fail.

Also, it appears that when you try to add the Journal entry with the code I've copied below,

you are only checking for error messages when the Add succeeds:

If oJE.Add = 0 Then

Dim num As Integer
oCompany.GetLastError(num, sStr2)
SBO_Application.MessageBox(sStr2)
Else
SBO_Application.MessageBox("Import was successful!")
oJE.SaveXML("c:\JournalEntries" + Str(oJE.Number) + ".xml")
End If

I think that the first line of code, above, should be if oJE.Add <> 0 then....

Are you getting your message that says "Import was successful!")?

Former Member
0 Kudos

Dear Sir,

In fact the problem was in the date format that i was adding it at the begining.

but now i have another problem which is when i have 2 differents accountign entries to be added consecutive this code add only the first entry and not the second, can you please advive

thanks in advance and Best Regards

Former Member
0 Kudos

I think you know that the "first line is always "free"" when it comes to adding a document with line items. So that means you only want to do the oJE.Lines.Add when adding lines other than the first.

The way I always handle adding lines to an object is something like this

dim LineAdded as boolean '(above your loop)

then at the top of the loop:

If LineAdded = true then

oJE.Lines.Add

endif

LineAdded = true

oJE.Lines.property = ...

Tha way you won't be doing a line add the first time, but you won't be doing it an extra time at the end, either.

HTH

Answers (1)

Answers (1)

Former Member
0 Kudos

Dear Sir,

I found the problem, it was in the date format. But now i have another proble which is when i try to