Community
Showing results for 
Search instead for 
Do you mean 
Reply

Very Frustrated!! Iterating Through Field Collections

Tuned Listener
Posts: 18
Country: United States

Very Frustrated!! Iterating Through Field Collections

Hello All,

 

I am having trouble filtering through contact record fields looking for phone number fields in C#.  ContactFields represents as a Contact.ContactFieldsCollection but how can I access this collection and filter through it? I can get at specific fields IF I know the name of the field with  

sDestination = CurrentContact.ContactFields["Contact.Phone"].ToString(); which will return the value of the field by this name.

 

I have tried:

foreach (object obj in CurrentContact.ContactFields)

{

MessageBox.Show("Loopy D Do");

}

 

which does not get me anywhere and :

 

foreach (Contact.ContactFieldCollection obj in CurrentContact.ContactFields)

{

MessageBox.Show("Loopy D Do");

}

 

fails as well. How do you get at these fields to find out what they are and work with them?

 

TIA

JB

Nickel Super Contributor
Posts: 441
Country: UK

Re: Very Frustrated!! Iterating Through Field Collections

In vb but you get the idea...

 

Dim cFields() As Act.Framework.Contacts.ContactFieldDescriptor = ActApp.ActFramework.Contacts.GetContactFieldDescriptors For Each field As Act.Framework.Contacts.ContactFieldDescriptor In cFields If field.ACTFieldType = Act.Framework.Database.FieldDataType.Phone Then MsgBox(field.DisplayName) End If Next

Tom

Tuned Listener
Posts: 18
Country: United States

Re: Very Frustrated!! Iterating Through Field Collections

OK I have converted as such except for one thing. I am assuming you must have ActApp created elsewhere earlier in your code?

 

 

Act.Framework.Contacts.ContactFieldDescriptor[] cFields = ActApp.ActFramework.Contacts.GetContactFieldDescriptors;  foreach (Act.Framework.Contacts.ContactFieldDescriptor field in cFields)

{

if (field.ACTFieldType == Act.Framework.Database.FieldDataType.Phone)

{

MessageBox.Show(field.DisplayName.ToString());

}

else

{

//skip it it is not a phone field

}

}

Employee
Posts: 33
Country: USA

Re: Very Frustrated!! Iterating Through Field Collections

You don't really need an ActApp if you have a framework reference already in this case, it is just an easy way to get the current inuse framework in a plug in.
Tim Faust
ACT! R&D
Tuned Listener
Posts: 18
Country: United States

Re: Very Frustrated!! Iterating Through Field Collections

Yes but the override is throwing me.

 

Object browser shows public Act.Framework.Contacts.ContactManager[] GetContactFieldDescriptors() member of Act.....

 

I not not connecting on how to execute the GetContactFieldDescriptors() because...well I guess if I knew that then I wouldn't be asking.

 

This creates an array....................................named cfields.....and this should populate the array only it doesn't.

Act.Framework.Contacts.ContactFieldDescriptor[] cFields = ActApp.ActFramework.Contacts.GetContactFieldDescriptors

 Something is not clicking in my brain???

 

Thanks

JB

Tuned Listener
Posts: 18
Country: United States

Re: Very Frustrated!! Iterating Through Field Collections

OK Figured it out here. What was throwing me was the way VB handles references I was unfamiliar with. Here is the corrected code in C#.

 

objContactFieldDescriptors = References.ActApp.ActFramework.Contacts.GetContactFieldDescriptors(); foreach (ContactFieldDescriptor objContractFieldDescriptor in objContactFieldDescriptors)

{

if (objContractFieldDescriptor.ACTFieldType == FieldDataType.Phone)

MessageBox.Show(objContractFieldDescriptor.DisplayName);

}

 

This second way I prefer as it eliminates the need for extra work and code by passing the Phone data type right off the bat. 

 

objContactFieldDescriptors =
References.ActApp.ActFramework.Contacts.GetContactFieldDescriptors(new FieldDataType[]{ FieldDataType.Phone, FieldDataType.Number}); foreach (ContactFieldDescriptor objContractFieldDescriptor in objContactFieldDescriptors)

{

MessageBox.Show(objContractFieldDescriptor.DisplayName);

}

 

 

Thank You for getting me started.!!

JB