Working with Attributes

Attributes are a common tool within The Raiser’s Edge. I know of no organisation that does not have any constituent attributes. Yet the API treats them rather peculiarly. Unlike an import where you specify the category and description the Attribute record doesn’t store the category in plain text. This would be OK if you regularly referred to attributes with their code table id but you do not. They are referred to using the category text.

Like other child objects on a record you can obtain a collection of attributes for a top level object and you can loop through them. In order to know if you have found the correct attribute you need to know the attribute type id. How do you find this given the category? You need to create another object the Attribute Type Server object, give it the id of the attribute you are looping through and then see if you are looking at the right one.

Dim oAttrTypesServer As New CAttributeTypeServer
Dim oAttribute As IBBAttribute
Dim oAttributes As IBBAttributesAPI  

Dim sImpId As String
Dim sDescription As String
Dim sDate As String
Dim sComments As String
Dim sValue As String
Dim lTypeId As Long  

oAttrTypesServer.Init SessionContext
For Each oAttribute In Attributes  

lTypeId = oAttribute.Fields(Attribute_fld_ATTRIBUTETYPES_ID)  

Select Case (oAttrTypesServer.GetAttributeTypeDescription(lTypeId))  

Case "MyAttributeDescription"
sDescription = oAttribute.Fields(Attribute_fld_VALUE)
sImpId = oAttribute.Fields(Attribute_fld_IMPORTID)
sDate = oAttribute.Fields(Attribute_fld_ATTRIBUTEDATE)
sComments = oAttribute.Fields(Attribute_fld_COMMENTS)  

                    Exit For
            End Select   

Next oAttribute  

Set oAttrTypesServer = Nothing

The above code gets the attribute type id (the id of the attribute category), it looks up the descriptions for that id and then compares it against the category we want.

Obviously what would have been better would have been the ability to add an attribute filter so that you could filter by category but alas this did not happen so we are stuck with this rather round about way of tracking down the attribute we want.

You should note that a constituent may have multiple attributes of one category (if this is set up in Config) so that you may want to carry on looping until you have gathered all the attributes that have this category.