Start a new topic

Membership Records stay locked after Import

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


Hi Philip,

Be sure to call oMem.CloseDown. When in doubt, close it down (even if you didn't init it).

Best,
Jeff
Philip,

Your oMem object I assume is coming from oRec.Memberships.Item(1). If this is the case then it is initialized by RE and you will need to call CloseDown on it.

Additionally, every time you make a call to oRec.Memberships.Item(#) it is returning a new initialized object. It is suggested to always use a temporary variable when dealing with these collection objects as below.

Dim oTemp as CMembership
oTemp = oRec.Memberships.Item(1)
'Do some work
oTemp.CloseDown
oTemp = Nothing
Thanks Jeff and Nic for the fast responses!

I am using oMem like this:

Dim oMem as New Blackbaud.PIA.RE7.BBREAPI.Cmembership

For Each oMem in oRec.Memberships
strCurrentMem = oMem.CurrentCategory
Next

I will try to close it again. Last time it gave me an error when I included: oMem.CloseDown in my code. I will let you know
Put Nic's code INSIDE your For..Next loop, otherwise you will get an error.

Jeff
Thanks. I have done more testing and tried both Scenarios:
1.
Dim oMem as New Blackbaud.PIA.RE7.BBREAPI.Cmembership

For Each oMem in oRec.Memberships
strCurrentMem = oMem.CurrentCategory
Next

...

oMem.CloseDown
oMem = Nothing

2.
Dim oMem as New Blackbaud.PIA.RE7.BBREAPI.Cmembership

For Each oMem in oRec.Memberships
strCurrentMem = oMem.CurrentCategory
oMem.CloseDown
oMem = Nothing
Next
...

Both case give me the same results. The Membership gets issued but it is locked to that Instance of RE.

Any other Ideas?
Hi Philip,

Is this ALL the custom code in your profile? It's hard to say without seeing that.

Jeff

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,

Because you aren't actually modifying the records that you load through code, you could load them read only. To do this you will need the system ID however.

Dim oRec As New Blackbaud.PIA.RE7.BBREAPI.CRecord
oRec.init(import.SessionContext)
oRec.LoadByField(Blackbaud.PIA.RE7.BBREAPI.bbRECORDUniqueFields.uf_Record_CONSTITUENT_ID, strAddoID)
Dim SystemID as integer = oRec.Fields(Blackbaud.PIA.RE7.BBREAPI.ERECORDSFields.RECORDS_fld_ID)
oRec.CloseDown
oRec = new Blackbaud.PIA.RE7.BBREAPI.CRecord
oRec.Init(Import.SessionContext)
oRec.Load(SystemID,True)

The membership objects served up from oRec.Memberships will also be read only.
Login or Signup to post a comment