Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Tuned Listener
bchristie
Posts: 14
Country: United States
Message 1 of 11 (4,147 Views)

Pull contact by field name

Hello!

 

<< I apologize sincerely if this has been answered but I've done searches and haven't found a solution (or at least one I can grasp). This may in fact just be an issue with me not understanding the data type and the names for everything. Anyhow: >>

 

I am looking to retrieve a contact from ACT! based on a field value (in this instance it's by email, but could possibly be by first/last name, phone, or what-have-you). I have faced and accomplished the following thus far, but please let know if I need to include anything else to tackle this solution:

 

- Acquired Act.Framework.dll from the CD

- Referenced Act.Framework.dl & Act.Shared.Collections.dll

- Established a connection (Act.Framework.ActFramework & .LogOn)

 

From there, I am looking for a way to set out a search to grab a contact that matches the field value I want. I'm running 2007 9.0 is that helps, any advice or code is very much appreciated.

 

Thank you,

Brad

Please use plain text.
Nickel Super Contributor
Tdavis
Posts: 441
Country: UK
Message 2 of 11 (5,233 Views)

Re: Pull contact by field name

From the sdk samples...

[Visual Basic] Overloads Public Function LookupContactsReplace( ByVal criteria As Criteria, ByVal includePrivate As Boolean, ByVal includeUsers As Boolean ) As ContactLookup 'Example 1 Dim cLookup As ContactLookup Dim lCriteria() As Criteria Dim includePrivate As Boolean Dim includeUsers As Boolean . . . cLookup = ActFwk.Lookups.LookupContactsReplace(lCriteria, includePrivate, includeUsers) 'Example 2 'This example populates a ContactList with a lookup of 'contacts based on the State and Last Name fields Dim sFieldName1, sFieldName2 As String Dim cColumn1, cColumn2 As CriteriaColumn Dim oOperator1, oOperator2 As OperatorEnum Dim sValue1, sValue2 As String Dim cLookup As ContactLookup Dim cList As ContactList 'initialize some varables sFieldName1 = "BUSINESS_STATE" sFieldName2 = "LASTNAME" oOperator1 = OperatorEnum.EqualTo oOperator2 = OperatorEnum.StartsWith sValue1 = "WA" sValue2 = "H" 'Get the column(s) to lookup on cColumn1 = ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT", sFieldName1, True) cColumn2 = ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT", sFieldName2, True) 'Create an array to hold all of the lookup criteria. Dim lCriteria() As Criteria = {New Criteria(LogicalOperator.And, 0, 0, cColumn1, oOperator1, sValue1), _ New Criteria(LogicalOperator.End, 0, 0, cColumn2, oOperator2, sValue2) _ } 'Create the Lookup cLookup = ActFwk.Lookups.LookupContactsReplace(lCriteria, True, True) 'Set our contact list to the lookup cList = cLookup.GetContacts(Nothing) MessageBox.Show(cList.Count.ToString())

 

 

Tom

Please use plain text.
Tuned Listener
bchristie
Posts: 14
Country: United States
Message 3 of 11 (5,210 Views)

Re: Pull contact by field name

Thank you very much Tom. i was looking though those but didn't see the example I needed I guess.

 

Works terrific now, I appreciate your help!

Please use plain text.
Tuned Listener
bchristie
Posts: 14
Country: United States
Message 4 of 11 (5,183 Views)

Re: Pull contact by field name

Okay, so I got that working (thank you) but have run in to a new problem:

 

I am attempting to programatically update a record in ACT by pulling the contact by email address, altering it [the email address], re-saving it, then attaching a note. Now, i have the grab part (to an Act.Framework.Contacts.Contact object) but when i attempt to alter the .Fields["TBL_CONTACT.BUSINESS_EMAIL",true] and call .Update() my contact's gone.

 

this has to be me not doing things in the right order, or in a manner that ACT! is not liking. Can someone point me in the right direction? I have the following thus far:

 

 

public Act.Framework.Contacts.ContactList GetContactsFromEmail(String Email) { if (this.m_Act.IsLoggedOn) { Act.Framework.Lookups.CriteriaColumn actColumn = this.m_Act.Lookups.GetCriteriaColumn("TBL_CONTACT", "BUSINESS_EMAIL", true); Act.Framework.Lookups.Criteria[] actCriteria = { new Act.Framework.Lookups.Criteria(Act.Framework.Lookups.LogicalOperator.End, 0, 0, actColumn, Act.Framework.Lookups.OperatorEnum.EqualTo, Email) }; Act.Framework.Lookups.ContactLookup actLookup = this.m_Act.Lookups.LookupContactsReplace(actCriteria, true, true); Act.Framework.Contacts.ContactList actContacts = actLookup.GetContacts(null); return actContacts; } return null; } public bool AttachNote(Act.Framework.Contacts.Contact actContact, String actNote) { if (this.m_Act.IsLoggedOn) { Act.Framework.Notes.NoteType actNoteType = new Act.Framework.Notes.NoteType(Act.Framework.Notes.SystemNoteType.Note); Act.Framework.Notes.Note actNewNote = this.m_Act.Notes.CreateNote(actNoteType, actNote, System.DateTime.Now, false, actContact); return (actNewNote != null); } return false; } public bool MarkAsBad(Act.Framework.Contacts.Contact actContact) { if (this.m_Act.IsLoggedOn) { try { // Update the email as bad... actContact.Fields["TBL_CONTACT.BUSINESS_EMAIL", true] = "BAD - " + actContact.Fields["TBL_CONTACT.BUSINESS_EMAIL", true]; actContact.Update(); // now, add the note... return this.AttachNote(actContact, "Bounced email"); } catch (Exception ex) { throw new Exception(String.Format("MarkAsBad failed with {0}", actContact.FullName), ex); } } return false; }

 The idea being you use GrabContactsByEmail to get the contact list, then iterate through the list and update (MarkAsBad) the contacts to prefix the email with "BAD_-_" (where _ = space), then add a note (AttachNote). Any pointers?

 

Thanks once again,

Brad

 

 

Please use plain text.
Copper Contributor
Carlton_Jones
Posts: 98
Country: United States
Message 5 of 11 (5,166 Views)

Re: Pull contact by field name

Boiled down what you were doing to this....

 

Contact cContact = ActFwk.Contacts.GetMyRecord(); // Update the email as bad... cContact.Fields["TBL_CONTACT.BUSINESS_EMAIL", true] = "BAD - " + cContact.Fields["TBL_CONTACT.BUSINESS_EMAIL", true]; cContact.Update(); Act.Framework.Notes.NoteType actNoteType = new Act.Framework.Notes.NoteType(Act.Framework.Notes.SystemNoteType.Note); Act.Framework.Notes.Note actNewNote = this.ActFwk.Notes.CreateNote(actNoteType, "Bad Email Address!", System.DateTime.Now, false, cContact);

 

 

 

And it works fine.

 

Scoping problem?

What is the error your getting?

 

Hope this helps,

Carlton Jones
Sage Software
Please use plain text.
Tuned Listener
bchristie
Posts: 14
Country: United States
Message 6 of 11 (5,097 Views)

Re: Pull contact by field name

As you can see from the code, I'm using a few function to go back and forth with the contact information and references. I don't see anythign odd-ball that would do this. I have to be transferring some level of detail with the Update call as it kills the contact I'm referencing.

 

When you pull the record data using the search I method listed above, is that grabbing all data? All these examples list "GetMyRecord" but could I see the same example with a search matching the email "bchristie@abc.com"?

Please use plain text.
Copper Contributor
Carlton_Jones
Posts: 98
Country: United States
Message 7 of 11 (5,093 Views)

Re: Pull contact by field name

Since I am not looking at your project and seeing the complete picture it is always hard to say where the problem is.

 

While I don't know if this will help, I do know that it works. Ran it on the demo to change all the @CHTechONE.com to 'bad' email addresses.

 

 

//Save Current Changes Contact cContact = ActApp.ApplicationState.CurrentContact; cContact.Update(); //Performing Lookup ////////////////////////////////// CriteriaColumn cColumn1; string sValue1 = "@CHTechONE.com"; ContactLookup cLookup; ContactList cList; //Get the column(s) to lookup on cColumn1 = ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT", "BUSINESS_EMAIL", true); //Create an array to hold all of the lookup criteria Criteria[] lCriteria = new Criteria[] {new Criteria(LogicalOperator.End, (byte)0, (byte)0, cColumn1, OperatorEnum.Contains, sValue1)}; //Create the Lookup cLookup = ActFwk.Lookups.LookupContactsReplace(lCriteria, true, true); //Set our contact list to the lookup cList = cLookup.GetContacts(null); //Options..... //ActApp.ApplicationState.SetCurrentContactList(cList, null); //ActApp.UIContactManager.ShowDetailView(); //Change 'Bad' emails foreach (Contact c in cList) { // Update the email as bad... c.Fields["TBL_CONTACT.BUSINESS_EMAIL", true] = "BAD - " + c.Fields["TBL_CONTACT.BUSINESS_EMAIL", true]; c.Update(); Act.Framework.Notes.NoteType actNoteType = new Act.Framework.Notes.NoteType(Act.Framework.Notes.SystemNoteType.Note); Act.Framework.Notes.Note actNewNote = this.ActFwk.Notes.CreateNote(actNoteType, "Bad Email Address!", System.DateTime.Now, false, c); }

 

 

Hope this helps,

 

Carlton Jones
Sage Software
Please use plain text.
Tuned Listener
bchristie
Posts: 14
Country: United States
Message 8 of 11 (5,059 Views)

Re: Pull contact by field name

Essentially, I have these methods in a self-contained class that when instantiated established the ACT framework connection and checks for confirmation of connection. Likewise, on destroy it cleans up the connection. within this class, I use the methods to query and update the values in ACT! (based on  the "Contact" object being passed through the methods). For instance:

 

// init
ActDDB ACT = new ActDB("user","pass");

// grab the contactList based on the email value (realistically
// this will 99.9% of the time be one contact coming back, so I
// will check for at least one member, and grab the first element
// in the list
ContactList cList = ACT.GetContactFromEmail(varWithEmail);

// Okay, check for a valid return with at least one member. use
// that member and update it
if (cList != null && cList.Count > 0)
ACT.MarkAsBad(cList[0], "Bounced Email");

 


 That's in my form under a click event. I have a MIME email being parsed grabbing email addresses and then taking those addresses and finding them in ACT!. if a match is found, I want to update those emails with the email prefix, and add a note. Again, this deletes the contact every time I've tried it. Am I passing these objects wrong? I don't fully understand the object model, so I'm in the dark as to how the ACT object does updated and referencing, but from what I can collect this looks feasible.

 

Again, thank you very much for your patience and assistance.

 

Brad

Please use plain text.
Copper Contributor
Carlton_Jones
Posts: 98
Country: United States
Message 9 of 11 (4,950 Views)

Re: Pull contact by field name

Boiling this down to its simplest form might give you some insight on why you'd be loosing contacts. Which is:

 

 

Contact c = HoweverYouSetYourContact(); // Update the email as bad... c.Fields["TBL_CONTACT.BUSINESS_EMAIL", true] = "BAD - " + c.Fields["TBL_CONTACT.BUSINESS_EMAIL", true]; c.Update();

 

I see nothing in your provided samples that should be deleting contacts.  

 

Did you try the sample above out on the demo?

 

Carlton Jones
Sage Software
Please use plain text.
Tuned Listener
bchristie
Posts: 14
Country: United States
Message 10 of 11 (4,912 Views)

Re: Pull contact by field name

Okay, i think I got it this time. It may have just been my search criteria to confirm changes (I would search, by email, in act to confirm the contact information, then run the program, then return to act and do a refresh only to find the contact absent). But just as confirmation, because I assume rights would propagate to the DSK, if I have add and modify rights only I should be safe against  deleting an entire contact, correct?

 

Once again, I appreciate all the informaiton you've given and the time you've taken to answer my questions. I think I'm getting a more firm understanding on how this SDK works, with the exception of SortCriteria. Not sure I understand the basis of that yet,  but I think that just involves tinkering and trial and error...

Please use plain text.