API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

Creating CashBook Entry


I am attempting to use the API to create a high number of cashbook entries, and received an e-mail about using many calls to the API.

Therefore I would like to optimize the code to do the least amount of calls when creating an entry, but I cannot find any examples, and the documentation appears to be an extract of methods, without any examples.

This is my code to create a cashbook entry:

Dim objAccount As IAccount
                        Dim objContraAccount As IAccount

                        objAccount = objSession.Account.FindByNumber(1010)
                        objContraAccount = objSession.Account.FindByNumber(6820)

                        Dim objEntry As ICashBookEntry
                        objEntry = objSession.CashBookEntry.CreateFinanceVoucher(objCashBook, objAccount, objContraAccount)

                        objEntry.Currency = objSession.Currency.FindByCode(EUR)
                        objEntry.VatAccount = objSession.VatAccount.FindByVatCode(U25)
                        objEntry.VoucherNumber = 5000
                        objEntry.Amount = -100
                        objEntry.AmountDefaultCurrency = -745
                        objEntry.Date = New Date(2011, 5, 23)
                        objEntry.Text = Ordre Nummer

                        Dim objData As ICashBookEntryData
                        objData = objSession.CashBookEntryData.GetData(objEntry)


From what I could gather from the e-mail, each time I do a objEntry., it gives an API call.

How can I create a new entry with these data's without calling the API too many times?

Best regards,

Brian Binnerup
created May 26, 2012 by Binnerup
0% Accept Rate
Q 1 A 0 C 0

1 Answer

Hi Brian,

By creating youre entries in batches you can minimize your API calls quite a lot.

You might be able to use this as inspiration.

    Protected Friend Sub CreateCashBookEntries()
        Dim NumberOfBatches As Integer
        Dim BatchIteration As Integer
        Dim BatchCurrentSize As Integer
        Dim BatchEntries(MeBatchSize - 1) As ICashBookEntryData
        Dim starttid As Date
            NumberOfBatches = CInt((CashbookEntriesGetUpperBound(0) + MeBatchSize - 1) / MeBatchSize)

            For BatchIteration = 0 To NumberOfBatches Step 1

                BatchCurrentSize = MeBatchSize
                If BatchIteration = NumberOfBatches - 1 Or CashbookEntriesGetUpperBound(0)  MeBatchSize Then
                    BatchCurrentSize = CashbookEntriesGetUpperBound(0) Mod MeBatchSize
                    ReDim BatchEntries(BatchCurrentSize - 1)
                End If

                ArrayCopy(CashbookEntries, BatchIteration * MeBatchSize, BatchEntries, 0, BatchCurrentSize)

                If BatchCurrentSize  MeBatchSize Then Exit For
            Next BatchIteration

        Catch ex As EconomicApiException
        End Try
    End Sub

Please be aware that the recommended batchsize is somewhere between 500 and 1000 entries. If you make larger matches you might get a timeout.

answered May 28, 2012 by marj
Visma e-conomic A/S