Community
Showing results for 
Search instead for 
Do you mean 
Reply

Get list of Contacts by (custom) field value, through .NET

Copper Super Contributor
Posts: 88
Country: USA

Get list of Contacts by (custom) field value, through .NET

Hi. I'd like to get a list of Contacts that have data in a particular field.

 

I want to have the list so that when a user puts any data in a particular field, I could filter the Contacts for those Contacts that have an entry in that field.

 

I don't know if it would be better to do a dynamic Group and get it's members, or do a Lookup.

 

Any suggestions? If so, would you post some (VB) code as an example?

 

Thanks!

 

Kim

Copper Super Contributor
Posts: 112
Country: Australia

Re: Get list of Contacts by (custom) field value, through .NET

[ Edited ]
Dim cl As Act.Framework.Contacts.ContactList

'which field you want to test
Dim field As Act.Framework.MutableEntities.MutableEntityFieldDescriptor
field = ActApplication.Instance.ActFramework.Contacts.GetMutableEntityFieldDescriptor("ACTFieldToTestName", FieldNameType.Alias)

'what sort of test do you want to do to the selected field
Dim fCriteria() As Act.Framework.ComparisonFilterCriteria = New Act.Framework.ComparisonFilterCriteria() _
                {New Act.Framework.ComparisonFilterCriteria(field, Act.Framework.ComparisonFilterCriteria.Operation.Is, "StringToTestFor")}

'build a contact list based on your field and criteria
cl = ActApplication.Instance.ActFramework.Contacts.GetContacts(Nothing, fCriteria) '<-- instead of Nothing you can pass in a SORT 

'have the ACT UI display only the contacts that matched
ActApplication.Instance.UILookupManager.LookupContacts(cl)

 this is just one way, there are many different ways.. you can also change ActApplication.Instance to your ActApp object if you have one

hope that helps

Copper Super Contributor
Posts: 88
Country: USA

Re: Get list of Contacts by (custom) field value, through .NET

OK, I'd definitely a newbie...

 

Here's the pseudocode I'm trying to do:

 

OK         1. Log on to my ACT!2011 database.

HELP!   2. Filter for a ContactList that uses as a Filter: Contact Field "HasDataInIt" contains data (is not blank).

HELP!   3. End up with a dynamic list in .NET that contacts basic Contact info and the "HasDataInIt" field.

OK         4. Work with the data in the .NET list.

HELP!   5. REPLACE the data in the "HasDataInIt" field with Nothing, dynamically removing that Contact from the .NET list. 

OK         6. Keeping working with the .NET list, repeating steps 3 and 4 until the .NET list is empty.

 

That's it. Basically, I'm having trouble coming up the the dynamic .NET list based on the Contact "HasDataInIt" field containing data.

 

I really appreciate any help you can give.

 

Kim

Copper Super Contributor
Posts: 112
Country: Australia

Re: Get list of Contacts by (custom) field value, through .NET

what do you mean by dynamically?? are you wanting this contactlist to be inside some vb.net code, or visually inside ACT as a Contact List View?

 

 

Dim cl As Act.Framework.Contacts.ContactList

Dim field As Act.Framework.MutableEntities.MutableEntityFieldDescriptor
field = ActApplication.Instance.ActFramework.Contacts.GetMutableEntityFieldDescriptor("HasDataInIt", FieldNameType.Alias)
Dim fCriteria() As Act.Framework.ComparisonFilterCriteria = New Act.Framework.ComparisonFilterCriteria() _
                {New Act.Framework.ComparisonFilterCriteria(field, Act.Framework.ComparisonFilterCriteria.Operation.IsNot, Act.Framework.ComparisonFilterCriteria.NULL_STRING)}
cl = ActApplication.Instance.ActFramework.Contacts.GetContacts(Nothing, fCriteria)
For Each c As Act.Framework.Contacts.Contact In cl
      field.SetValue(c, DBNull.Value) 
      c.Update()
Next

 this creates a contactlist of contacts where the field HasDataInIt as NULL.. you can try string.empty (so you might need to test for both

the code then fills the contactlist based on the filter and then loops through each contact settings that field to NULL and saving it

 

to test for both NULL or an empty string (should work)

 

Dim fCriteria() As Act.Framework.ComparisonFilterCriteria = New Act.Framework.ComparisonFilterCriteria() _
                {New Act.Framework.ComparisonFilterCriteria(field, Act.Framework.ComparisonFilterCriteria.Operation.IsNot, Act.Framework.ComparisonFilterCriteria.NULL_STRING), _
                New Act.Framework.ComparisonFilterCriteria(field, Act.Framework.ComparisonFilterCriteria.Operation.IsNot, String.Empty)}

a field that has never had data would be NULL, but if it has had data in it and you just deleted the text with backspace then its not NULL in the database anymore its just an empty string 

 

 

 

Copper Super Contributor
Posts: 88
Country: USA

Re: Get list of Contacts by (custom) field value, through .NET

Thanks for your reply.

 

In answer to your questiion, I want to end up with a list in .NET of the Contacts that I have filtered.

 

Ok, I am able to get a ContactList of the names I want.

 

Now, I want to work with fields in that ContactList. If I want the name and address fields, and my "HasDataInIt" field, how do I access them? I want to go to each Contact in the ContactList, get the values of select fields, update one or more field values, and go to the next Contact in the ContactList until there are no more Contacts in the list.

 

My real question is: how do I isolate one Contact at a time, and work with the Fields in that Contact record?

 

Again, thanks for your help and reply.

 

Kim

Copper Super Contributor
Posts: 112
Country: Australia

Re: Get list of Contacts by (custom) field value, through .NET

using the for each list i have already posted you can loop each contact one at a time and test for things and work with each field..
some fields are exposed like c.LastName, c.FirstName,c.ID etc etc.. other you access like
c.Fields("FieldName", Act.Framework.MutableEntities.FieldNameType.Alias)
Copper Super Contributor
Posts: 88
Country: USA

Re: Get list of Contacts by (custom) field value, through .NET

Thank you so much for your help!

 

I am now able to pull up a dynamic list of Contacts based on a Field containing data. Your help was vital in accomplishing this.

 

It amazes me how complicated it seems to be to write the code to accomplish this.

 

Any suggestions for websites and/or other resources to learn how to write code through the ACT! SDK and .NET?

 

Blessings to you and your family.

 

Kim

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: Get list of Contacts by (custom) field value, through .NET

Just a quick note to bear in mind. If you are dealing with a very large list of MutableEntities, you might find that your code preforms faster if you use the OLEDB provider to access the list of MutableEntity objects and refer to them directly via their GUID ref.
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Super Contributor
Posts: 88
Country: USA

Re: Get list of Contacts by (custom) field value, through .NET

I've notinced that the code speed is fine. What I've also noticed is that the login routine using Act.Framework seems to take a long time.

 

Is there any "quick login" available in ACT! through VB.NET?

Copper Super Contributor
Posts: 112
Country: Australia

Re: Get list of Contacts by (custom) field value, through .NET

there is only one login way.. no quick way..

my question is what are you making.. a plugin? control? app?
if its a plugin or control then you dont need to login because ACT once running is already logged in so you just use ActAppliction.Instance so you dont need to login.. but for an application you have to do a login, but only do it once then store it so you dont have to do it over and over