Following my previous article on creating a batch with a notepad I am following it up with a some code that adds attributes. This is more or less shown on the Blackbus thread that I referenced but I wanted to clarify some of the steps having gone through the procedure myself.
Like the example with the notepad you still need to add a reference to the “other” batch API. Unlike notepads however there are some steps you need to take in order to set the batch up correctly. In the notepad example you need to give the notepad type (in text) and the notes and reference the correct entries in the temporary object (CTempObject). With attributes it is somewhat more difficult.
Firstly you need to specify the attribute type. At first I thought this should be done in the same way as with the notepad type. However this is not the case. When you set up the batch you need to specify the attribute type id too. The code below shows how this is done.
Before you can call this you need to determine the attribute type id as follows:
Dim typesServer as New CAttributeTypeServer
typesServer.Init(SessionContext)
id = typeServer.GetAttributeTypeID("my attribute category", bbAttributeRecordTypes.bbAttributeRecordType_GIFT)
SetupBatchAttributeField(batchFields.Add(), EattributeFields.Attribute_fld_VALUE, id)
SetupBatchAttributeField(batchFields.Add(), EattributeFields.Attribute_fld_COMMENTS, id)
SetupBatchAttributeField(batchFields.Add(), EattributeFields.Attribute_fld_ATTRIBUTEDATE, id)
The batch set method is defined below:
Private Sub SetupBatchAttributeField(ByVal batchField As CBatchField, ByVal attField As EattributeFields, ByVal attId As Integer)
With batchField
.Fields(EBatchFieldFields.BatchField_fld_MetaObjectId) = bbMetaObjects.bbmoGIFT_ATTRIBUTE
.Fields(EBatchFieldFields.BatchField_fld_FieldNumber) = attField
.Fields(EBatchFieldFields.BatchField_fld_ObjectID) = attId
End With
End Sub
There are many other ways that seem much more intuitive but from what I can gather this is the way you have to set up the batch. When you go into the batch you see that the column headers refer to the attribute you are adding (“my attribute category” in the above case).
Once you have set up your batch you add the values in the same way as the notepad – assigning them to the temp object directly. There is no need to assign the attribute type id in this way though as it was assigned during the batch set up.
When you then look at the batch you see that the attribute columns have headers like My attribute Category Description, My attribute Category Comment, My attribute Category Date, etc.
Thanks for that code. It was very helpful.
Also just found out how to add more then one instance of the same attribute, it is fairly easy. Just increment the field BatchField_fld_ObjectSequence for each time you want to include the same attribute.
Whilst porting code to .Net I relearnt the importance of this post.
Note that when declaring Ctemprecords and ctemprecord variables ensure that
you use the Blackbaud.PIA.RE7.BatchData versions and note the Blackbaud.PIA.RE7.BBREAPI versions.
Using the wrong version will also result in nasty exceptions when set attributes values etc..