Start a new topic

email logic

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


Wayne,

You're pretty much correct on the first one. Phones and emails live on addresses so you would need to either stick to the preferred address or loop through all phones/emails on all addresses.

The second one is more complicated, but it is possible. You would need to do all of the phone/email processing in this case and after you are done, set the email field blank in order to stop IOM from processing it again.
Great, I will work on that!
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
[code] 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 [/code]


Then this is what I have in my BeforeConstituentSave. Basically erasing the Email column in the import if it matches
[code] 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 [/code]

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?

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 Functio
n


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,

You are in fact running this code in the wrong place. The BeforeConstituentSave method is fired after all information about the constituent has already been entered. You are going to want to move your code to the below sub.

Public Overrides Sub AfterConstituentOpen(ByVal oRec As Blackbaud.PIA.RE7.BBREAPI.CRecord, ByVal Cancel As ImportOM.API.iCancel)

End Sub

This may not have been obvious as it is not one of the default subs added to a new profile. To see a list of all subs we have exposed type out Overrides on a new line. More will be added in the future.
TRICKY
Ok, so I found the new function to override. Should I remove the line: MyBase.AfterConstituentOpen(oRec,Cancel)

Also, what does the AddressAdded function do? When is that fired?
Wayne,

You can remove the MyBase line if you like. The only instance where the MyBase line is useful is if you decide to override the ProperCase sub. Leaving it in will perform the normal proper casing as well as any custom rules you add.

The AddressAdded function only fires when a brand new address is added.
A last question a little off topic, is there a way for me to find the phone number of a specific type in the RE API or do I have to iterate through all of the numbers on a record until I find it?

Something like: oRec.PreferredAddress.Phones("email")

No, you will have to loop through them.

With all of the new events being added in the near future, I will make sure to update the API help document. This should make figuring out which methods are useful for what you are trying to accomplish.
Just to make sure I'm not breaking anything...

When I want to assign a new phone type to a record I can just do something like:

IBBPhone.Fields(EPhonesFields.Phone_fld_PhoneType) = "Email 1"

I don't need to refer to a type id or something like that? This works in the code, but I want to make sure I'm doing it correctly.
Wayne,

As long as the type already exists that will work fine. Otherwise you will need add the code table entry first.
Nic, I just want to thank you again for taking the time to answer these newbie questions about someone else's product! you guys are awesome!
Login or Signup to post a comment