Well that didn't work! Let's try that again...
I can't seem to get this to work. I think I don't understand the order of steps in the API.
I want to have a function that will not replace an email address on a record if it already exists in ANY phone type.
This is what I have in my Global.vb
Public Shared Function GetEmailType(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, sEmail As String) As String
Dim oAddr As CConstitAddress
Dim iPhone As IBBPhone
Dim sType As String = ""
oAddr = oRec.PreferredAddress
For Each iPhone In oAddr.Phones
If String.Compare(sEmail, iPhone.Fields(EPhonesFields.Phone_fld_Num), TRUE) = 0 Then
sType = iPhone.Fields(EPhonesFields.Phone_fld_PhoneType)
Exit For
End If
Next iPhone
Return sType
End Function
Then this is what I have in my BeforeConstituentSave. Basically erasing the Email column in the import if it matches
Public Overrides Sub BeforeConstituentSave(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, _
Cancel as ImportOM.API.iCancel)
'The main constituent record is about to be saved
If GlobalCode.GetEmailType(oRec, Import.Fields.GetByName("Email").Value) "" Then
' Do not replace the email
Import.Fields.GetByName("Email").Value = ""
MsgBox("Matched!")
Import.ShowRow()
End If
This compiles and runs. I get the pop-up "Matched!" and I get the ShowRow info that shows a blank email address, but somehow the email is still being recorded on the record as the "email" type (even though it's on there already as "spouse email").
Should I have the replacement call somewhere else? Should I be replacing something else?
Wayne Pozzar
I would like to do two things with email addresses:
1) I would like to make it so that if the email address already exists on the record (no matter the type) then don't replace "email" (as it would by default). There might be a combination of settings for this but I have not figured it out.
2) I would like the incoming email address to be set to type "email" (only if it is new) and move all of the old addresses up the email type chain. i.e. email -> email2, email2 -> email 3 etc. You already have the reverse of this but I want to have the newest email be the first one.
So when do I make these decisions in the API? Form what I can tell, the first time I have access to the RE record is in BeforeConstituentSave.
If, in that function, I say something like (pardon the pseudo-code):
bEmailExists = FALSE
For each sEmail in oRecord
if sEmail = Import.Fields("email").Value then
bEmailExists = TRUE
End If
Next
if bEmailExists Then
' Remove the value in the email column so that it is not set
Import.Fields("email").Value = ""
End If
Does that make sense? Better place/way to do this?
Same question for #2