Start a new topic

Making Constituent Codes Primary

Here is some code I wrote to make a constituent code "primary" when you add it

Call it in BeforeConstituentSave in Profile.vb using:

GlobalCode.ImportPrimaryConsCode(oRec, Import.Fields("YourConsCodeColumn").Value, Import)

Code for Global.vb below


' ImportPrimaryConsCode

' Wayne Pozzar 2014-03-05



'   This function will rearrange the constituent codes on the current record

' to place the desired constituent code in position 1 making it the "primary"

' code according to RE.


' oRec - The current constituent record (should be called in BeforeConstituentSave)

' sImportCode - The constituent code to be moved to position 1

' oImport - The current Import session


' None


  Public Shared Sub ImportPrimaryConsCode(oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, sImportCode As String, oImport As ImportOM.API.iImportSession)

  ' If the import field is blank then just leave

    If sImportCode = "" Then

      Exit Sub

    End If

    Dim sRECode As String ' current code in loop

    Dim oCCode As Blackbaud.PIA.RE7.BBREAPI.CConstituentCode ' ConsCode object for loop

    Dim iSequence As Integer ' sequence of current code in loop

    ' Go through all of the cons codes on the record and rearrange them

    For Each oCCode In oRec.ConstituentCodes

      ' Get the current code from RE


      ' Get the current sequence from RE

      iSequence = CInt(oCCode.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_SEQUENCE))

      ' Check the incoming code against this existing code

      If String.Compare(sRECode, sImportCode, True) = 0 Then

        ' Found the incoming code

        If iSequence = 1 Then

          ' The code is already in the right spot so we are done

          Exit For


          ' the code is not in the right spot so reassign it to the first position


          ' Now we are done since it goes in sequence order and we have already reassigned previous codes ahead one

          Exit For

        End If


        ' Not the correct code so move this one up one

        oCCode.Fields(Blackbaud.PIA.RE7.BBREAPI.ECONSTITUENT_CODEFields.CONSTITUENT_CODE_fld_SEQUENCE) = iSequence + 1

      End If

    Next oCCode

  End Sub

Login or Signup to post a comment