The whole code is a bit long so I did not want to post it unless really necessary. Below are 2 of the 4 subs + some Global code I am using. The other 2 sub are not referencing the oMem and the Global code is not being called so I did not include it here.
I also stripped it down a little bit (took out Case Statements, Debugging msgboxes etc.). It still has the basic functionality.
'***************
Imports Microsoft.VisualBasic
Imports System
'This code is specific to your current profile
Public Class Profile
Inherits ImportOM.API.ProfileBase
Public moSess As Blackbaud.PIA.RE7.BBREAPI.IBBSessionContext
Public Overrides Sub BeforeComputedColumns(Cancel as ImportOM.API.iCancel)
'Raw data straight from the file
'Use the Fields object to access the data
'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"
On Error GoTo ErrorHandler
'===============================================
'===============================================
'Check Current Membership Status of the Constituent in RE. If
'a membership is found it makes sure the correct membership transaction type
'is set and corrects it if necessary. This is important as if there is
'wrong data an exception occurs
'===============================================
'Check if there is an AddoID in the Import File
Dim strAddoID As String = import.Fields.GetByExcelName("A").Value
Dim strMemCat As string = import.Fields.GetByName("strMemCategory").Value
Dim strFlag As string
If strAddoID "" Then
If strMemCat "" Then
Dim strNewMembership As String = import.Fields.GetByName("strMemCategory").Value
Dim strTransactionType As String = import.Fields.GetByName("strTransactionType").Value
Dim strCurrentMem As String = ""
Dim oRec As New Blackbaud.PIA.RE7.BBREAPI.CRecord
Dim oMem As New Blackbaud.PIA.RE7.BBREAPI.CMembership
orec.init(import.SessionContext)
oRec.LoadByField(Blackbaud.PIA.RE7.BBREAPI.bbRECORDUniqueFields.uf_Record_CONSTITUENT_ID, strAddoID)
'Find Current Membership and assign Category to 'strCurrentMem'
For Each oMem In oRec.Memberships
strCurrentMem = omem.CurrentCategory
oMem.CloseDown
oMem = Nothing
next
'Compare Current Membership in RE against new Membership being Imported
' then correct the MembershipTransactionType in the importfile as needed.
Select Case strCurrentMem & "-" & strNewMembership
Case "Paid Annual-Paid Lifetime"
If strTransactionType = "Renewal" Then
import.Fields.GetByName("strTransactionType").Value = "Upgrade"
End if
Case ...
...
End Select
'Clean Up Objects
oRec.CloseDown
ORec = Nothing
Else
'executes if 'strMemCategory' = "" to prevent errors
' import.Fields.GetByName("NewMember").Value = ""
import.Fields.GetByName("strMemCategory").Value = ""
import.Fields.GetByName("datMemStartDate").Value = ""
import.Fields.GetByName("datAnnualExpireDate").Value = ""
import.Fields.GetByName("boIsLifetime").Value = ""
import.Fields.GetByName("currMembershipDues").Value = ""
import.Fields.GetByName("strTransactionType").Value = ""
import.Fields.GetByName("strLTType").Value = ""
import.Fields.GetByName("boPlaqueTrophy").Value = ""
import.Fields.GetByName("strMemNumber").Value = ""
End If
End If
End Sub
Public Overrides Sub AfterConstituentOpen(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, ByVal Cancel As ImportOM.API.iCancel)
'Check if there is an AddoID in the Import File
Dim strAddoID As String = import.Fields.GetByExcelName("A").Value
Dim strMemCat As String = import.Fields.GetByName("strMemCategory").Value
If strAddoID = "" Then
If strMemCat "" Then
'-----------------------------
Dim strNewMembership As String = import.Fields.GetByName("strMemCategory").Value
Dim strTransactionType As String = import.Fields.GetByName("strTransactionType").Value
Dim strCurrentMem As String = ""
Dim oMem As New Blackbaud.PIA.RE7.BBREAPI.CMembership
'Find Current Membership and assign Category to 'strCurrentMem'
For Each oMem In oRec.Memberships
strCurrentMem = omem.CurrentCategory
oMem.CloseDown
oMem = Nothing
Next
'Compare Current Membership in RE against new Membership being Imported
' then correct the MembershipTransactionType in the importfile as needed.
Select Case strCurrentMem & "-" & strNewMembership
Case "Free 6 Month-Paid Annual"
If strTransactionType = "Renewal" Or strTransactionType = "" Then
import.Fields.GetByName("strTransactionType").Value = "Upgrade"
End if
Case...
...
End Select
ElseIf strMemCat = ""
'Executes if 'strMemCategory' = "" to prevent errors
import.Fields.GetByName("strMemCategory").Value = ""
...
End If
Else
'When AddoID is not ""
End If
'Clean Up Objects
oRec = Nothing
End Sub
Philip Stender
Hello
I have a profile which I am using to import gifts and memberships. Before issuing (upgrade, renew etc) the membership the API is checking whether there is a current membership on the record.
First I thought that the issue is due to a memory leak of un-closed my objects, but checking into it I did close them. I am using the Records & Membership Objects. I close out each event like this:
oMem = Nothing '(I have not init this Object)
orec.CloseDown
oRec = Nothing
Is there something else you suggest I should do?
Philip