I am currently working on a project where I need to copy a gift record from one constituent to another. There are 213 fields on the regular gift object i.e. CGift. That is without looking at any of the other areas of the gift such as attributes, notepads, etc. It would take a lot of typeing to copy between each field so to do this I use the meta data that is supplied with each object.I use the following code:
Dim meta As IBBMetaField meta = CType(origGift, IBBMetaField) For i As Integer = 1 To meta.Count If meta.ReadOnly(i) = False Then newGift.Fields(i) = origGift.Fields(i) End If Next
Here I am using the original gift for my meta data. I use the ReadOnly method to determine whether or not I can enter data into the field. This prevents me from adding data to the Added By field, etc. But this is where the problem lies. Some fields are read only on the original gift but they are not on the new gift. The gift type field only becomes read only when you save it. What is more if the gift if posted then the fund, campaign, appeal, etc fields are also read only.
If we use the new gift’s meta data, very few of the fields are read. This way around we can enter data into fields that are read only on the original such as gift type and fund, etc. The problem is that other fields are not read only so that we end up copying over the constituent id, the import id and other values which should really be unique to the original gift.
Unfortunately there does not appear to be a happy medium. The only way around is to insert a select case looking at the value of i and excluding those id fields. It would have been nice if there had been some kind of indicator showing which fields were given values automatically by the system.