I have on several occasions expressed my delight about the arrival of the Batch API. I am still enthusiastic but somewhat war weary having spent this passed week trying to solve problems that have appeared. Clearly the Batch API was not rigorously tested before it was released as otherwise the sort of errors I am getting would not have appeared. In case you have been struggling too or in case you thinking about using this functionality here is what I have been up against.
Using the batch API consists of two parts; creating the batch and then populating the batch you have created. When you add records to a batch you load the CBatchAPI object either by name or id. You then use the child collection property of type CTemprecords in order to add a row to the batch. This is a similar concept to adding a notepad to a constituent:
Dim tempRecords as CTempRecords
Dim tempRecord as CTempRecord
tempRecords = batchAPI.tempRecords
tempRecord = tempRecords.Add
Now I have done this before and it has worked fine but when I tried it this time I got the error message (including the line spacing):
Init method must be called before using this object”
This was very confusing. The only object that has an
Init method is the
CBatchAPI and I certainly did initialize that. Like many error messages this is a red herring and a symptom of an internal API problem. After two frustrating days I get the code to work. Initially I was testing the code on version 7.82 against a SQL Server 2005 database. Now testing it on 7.82 against a SQL Server 2000 database it works. This appears to work with the 7.85 and 2005 combination so should not cause too many problems to the majority of people but it is not a good sign.
And to the other issue. I wanted to add the letter code to my batch. I didn’t need to populate it just ensure that it was there. I admit at this stage that I didn’t check the various alternatives that carefully. I thought that I should use the code:
GIFT_fld_AckLetterActionID. Seemed reasonable enough. It was next to the acknowledgement date and whether or not the gift had been acknowledged. (for reference this was the wrong code. It should have been:
GIFT_fld_Letter_Code). Once I had created the batch, I proceed to populated it. I then saved the batch and got the following error:
Run-time exception thrown : System.Runtime.InteropServices.COMException – General ODBC Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ‘,’.
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Once again this clearly shows an internal code problem. Now clearly I was using the wrong code in this case but the point is that a finished piece of software should not produce this kind of error message. It took me a while to hunt down the problem.
I stand by my claim that the Batch API is an extremely useful addition to the API tools available. However the fact that the procedures for setting up batches and getting data into the batches are not well defined and that there are a lot of erroneous errors appearing does not lend much confidence to the ability of the API to perform.