Start a new topic

Adding Constituent Code


I'm importing data that may or may not have an existing RE record.  If the record exists, I want to add some stuff and leave the "Staff" constituent code as is.

However, if the incoming data is NOT in RE, I want to add a constituent code of "Staff" and add a Date From from the import file which would be the Hire Date.

I get an error stating that the required field "Constituent Code" is not found. I'm thinking that it's something with the processing order?

Here is my code:

Public Overrides Sub BeforeConstituentSave(ByVal oRec As CRecord, ByVal Cancel As ImportOM.API.iCancel)
    MyBase.BeforeConstituentSave(oRec, Cancel)
Dim oCode As Blackbaud.PIA.RE7.BBREAPI.CConstituentCode
Dim lTypeId As String

For Each oCode In oRec.ConstituentCodes

        If lTypeId = "Staff"
            With oRec.ConstituentCodes.Add
                .Fields (Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_DATE_TO) = ""
            End with
            With oRec.ConstituentCodes.Add
                .Fields (Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_CODE) = "Staff"
                .Fields (Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_DATE_FROM) = import.Fields.GetByExcelName ("U").Value
            End with
        End If
End Sub




1 Comment

To add, provide the id of "Staff" as well as the literal. 

Future reference, you would also need the id to programmatically remove a constituent code.


I haven't tested this code, but should get you close to what you need:


Dim codeLiteral As String = "Staff"

Dim codeTablesServer As Blackbaud.PIA.RE7.BBREAPI.CCodeTablesServer = New Blackbaud.PIA.RE7.BBREAPI.CCodeTablesServerClass()

Dim iBBSessionContext As Blackbaud.PIA.RE7.BBREAPI.IBBSessionContext = oImport.SessionContext




Dim id As Integer = codeTablesServer.GetTableEntryID(codeLiteral, Blackbaud.PIA.RE7.BBREAPI.ECodeTableNumbers.tbnumConstituencies, false)


With oRec.ConstituentCodes.Add



        .Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_DATE_FROM) =  import.Fields.GetByExcelName("U").Value

End With

Login or Signup to post a comment