Community
Showing results for 
Search instead for 
Do you mean 
Reply

Get an email address for a contact

Accepted Solution Solved
New Member
Posts: 14
Country: United States
Accepted Solution

Get an email address for a contact

How does one find an email address for a contact?  The SDK is not clear on this point.

 

Thanks.


Accepted Solutions
Solution
Accepted by topic author rlieving
‎09-25-2015 03:20 AM
Nickel Super Contributor
Posts: 441
Country: UK

Re: Get an email address for a contact

Hi Rob,

There is documented somewhere but I can't find it now either.  Basically the contact fields can be accessed by either a real name or a display name. Eg. Contact.Fields("TBL_CONTACT.CONTACT",true) or Contact.Fields("Contact.Contact",false).  If you use the display name it can cause problems with spillover tables (There's not just TBL_CONTACT, your database can grow beyond this).  You can find all the fields and tables in your database in the fields structure detailed report in actdiag (Start -> Run -> ActDiag).  You can get also get all your fields as field descriptors in the SDK and itterate them that way.  I've put some samples below, hopefully they will make things a bit clearer.

Private Sub MessageBoxAllContactFields() 'this will display all contact fields 1 by 1 in a message box 'you can also choose to access other field properties this way 'first we must create an array to hold the fields Dim cFields() As Act.Framework.Contacts.ContactFieldDescriptor 'now we can get the fields using the contact manager cFields = ActFwk.Contacts.GetContactFieldDescriptors 'all we have to do now is iterate them For Each field As Act.Framework.Contacts.ContactFieldDescriptor In cFields MsgBox(field.Name & " " & field.ACTFieldType.ToString) Next End Sub Private Function GetFieldTrueName(ByVal displayName As String) 'this function will return a true fields name from a display 'name, this means you can use true names in your code to get 'around the spillover table problems 'first we get the contact fields again Dim cFields() As Act.Framework.Contacts.ContactFieldDescriptor cFields = ActFwk.Contacts.GetContactFieldDescriptors 'now iterate them checking for the display name For Each field As Act.Framework.Contacts.ContactFieldDescriptor In cFields If field.DisplayName = displayName Then 'name matches, return the tru field name Return field.Name End If Next End Function Private Sub ShowEmailAddress(ByVal Contact As Act.Framework.Contacts.Contact, ByVal emailFieldDisplayName As String) 'this sub will messagbox the contents of a contact's 'email field given the contact and the display name 'of the email field 'create a holder for the email address Dim emailAddress As String 'access the contact fields property and use the 'function above to find the true field name of the 'email field emailAddress = Contact.Fields(GetFieldTrueName(emailFieldDisplayName), True) 'check the email address isn't null If emailAddress <> "" Then MessageBox.Show("Contact's email is: " & emailAddress) Else MessageBox.Show("Contact's email field is empty") End If End Sub

 

Tom

 

View solution in original post


All Replies
Nickel Super Contributor
Posts: 441
Country: UK

Re: Get an email address for a contact

You would access it through the contact fields property eg:

 

Dim contact as act.framework.contacts.contact = actapp.applicationstate.currentcontact

dim emailAddress as string = contact.fields("contact.email",false)

msgbox(emailAddress)

 

Note that contact.email is just an example, your email field may be different, I think there are some samples in the SDK for accessing field values.

 

Tom

New Member
Posts: 14
Country: United States

Re: Get an email address for a contact

Tom:

 

Thanks for your message.  I tried your suggestion and it did not work in my Act 10 version.  

 

And perhaps the SDK lists the functionality somewhere, but I haven't found it anywhere.

 

I think the main issue for me is the way collections are accessed.  In the collections I typically use, one is given the option of using an integer to iterate through the collection and see what is there, helping the programmer to discover the collection.  In ACT collections, they only have string, late bound collections. Therefore, if one doesn't know the string, one is out of luck.  Turns out....I don't know the string - so I am out of luck.

 

Anyway, if you have any way for me to 'discover' the contact fields, that would go a long way for me.

 

Thanks,

 

Rob 

Solution
Accepted by topic author rlieving
‎09-25-2015 03:20 AM
Nickel Super Contributor
Posts: 441
Country: UK

Re: Get an email address for a contact

Hi Rob,

There is documented somewhere but I can't find it now either.  Basically the contact fields can be accessed by either a real name or a display name. Eg. Contact.Fields("TBL_CONTACT.CONTACT",true) or Contact.Fields("Contact.Contact",false).  If you use the display name it can cause problems with spillover tables (There's not just TBL_CONTACT, your database can grow beyond this).  You can find all the fields and tables in your database in the fields structure detailed report in actdiag (Start -> Run -> ActDiag).  You can get also get all your fields as field descriptors in the SDK and itterate them that way.  I've put some samples below, hopefully they will make things a bit clearer.

Private Sub MessageBoxAllContactFields() 'this will display all contact fields 1 by 1 in a message box 'you can also choose to access other field properties this way 'first we must create an array to hold the fields Dim cFields() As Act.Framework.Contacts.ContactFieldDescriptor 'now we can get the fields using the contact manager cFields = ActFwk.Contacts.GetContactFieldDescriptors 'all we have to do now is iterate them For Each field As Act.Framework.Contacts.ContactFieldDescriptor In cFields MsgBox(field.Name & " " & field.ACTFieldType.ToString) Next End Sub Private Function GetFieldTrueName(ByVal displayName As String) 'this function will return a true fields name from a display 'name, this means you can use true names in your code to get 'around the spillover table problems 'first we get the contact fields again Dim cFields() As Act.Framework.Contacts.ContactFieldDescriptor cFields = ActFwk.Contacts.GetContactFieldDescriptors 'now iterate them checking for the display name For Each field As Act.Framework.Contacts.ContactFieldDescriptor In cFields If field.DisplayName = displayName Then 'name matches, return the tru field name Return field.Name End If Next End Function Private Sub ShowEmailAddress(ByVal Contact As Act.Framework.Contacts.Contact, ByVal emailFieldDisplayName As String) 'this sub will messagbox the contents of a contact's 'email field given the contact and the display name 'of the email field 'create a holder for the email address Dim emailAddress As String 'access the contact fields property and use the 'function above to find the true field name of the 'email field emailAddress = Contact.Fields(GetFieldTrueName(emailFieldDisplayName), True) 'check the email address isn't null If emailAddress <> "" Then MessageBox.Show("Contact's email is: " & emailAddress) Else MessageBox.Show("Contact's email field is empty") End If End Sub

 

Tom

 

New Member
Posts: 14
Country: United States

Re: Get an email address for a contact

Thanks Tom - this is very helpful.

 

Rob