08-26-2014 09:10 AM
ISSUE:
I'm having trouble receiving certain data back when looking up contacts by email.
CONTEXT:
To get contacts by email, to find duplicates. These duplicates will be managed after they are retrieved
I'm using this method to get contacts by email like so:
public ContactList getContactByEmail(string email) { ACTFM.LogOn((path), user, pass); //declare CriteriaColumn cColumn; OperatorEnum oOperator; string sValue; ContactLookup cLookup; ContactList cList; //init oOperator = OperatorEnum.EqualTo; sValue = email; cColumn = ACTFM.Lookups.GetCriteriaColumn("TBL_CONTACT", "BUSINESS_EMAIL", true); //hold lookup in array USE THE ***END*** method Criteria[] lCriteria = new Criteria[] { new Criteria(LogicalOperator.End, (byte)0, (byte)0, cColumn, oOperator, email) }; //create lookup cLookup = ACTFM.Lookups.LookupContactsReplace(lCriteria, true, true); cList = cLookup.GetContacts(null); ACTFM.LogOff(); return cList; }
And inside another method I make the call to the ContactList method like so:
ContactList similarsList = act.getContactByEmail(row.Cells[3].Text); foreach (Act.Framework.Contacts.Contact con in similarsList) { Debug.WriteLine("a contact: " + con.FirstName); }
When doing so at line:
Debug.WriteLine("a contact: " + con.FirstName);
I get the error: "Object reference not set to an instance of an object".
----------------------------------------------------------------------------------------------------------------------------------------------------------
Interestingly enough when I use "con.ID" like so:
Debug.WriteLine("a contact: " + con.ID);
Instead of:
Debug.WriteLine("a contact: " + con.FirstName);
I get the expected ID's of the contacts I am looking up. So I know the code is working to some extent?
QUESTION:
What could be causing the code to fail when trying to access the contact fields, but work when accessing the ID field?
08-26-2014 02:18 PM - edited 08-26-2014 02:22 PM
Yeah I tested to see what was going on. The weird thing was that I have access to the ACT CRM and I could see the contacts, and that they did indeed have the values inside that I was trying to retrieve.
I've since solved the issue, though. It turns out that doing:
ACTFM.Logoff();
before accessing and utilzing the properties of con, wiped out the memory that the instance of ContactList was referenced to. I'm assuming this is a security feature, so that even after legitimately accessing the data, you cannot access it unless logged in. Sigh.
Thanks for your reply though, had I still been in the dark, it would have been a breath of fresh air!
08-26-2014 12:07 PM
Hi 2gen,
Have you done any work to try and find out if any of your objects are null?
You should check cColumn, cLookup and cList. Also check how many contact exist in cList using
MessageBox.Show(cList.Count.ToString());
If this doesn't point you to the answer please just let me know and I'l try and assist further.
Regards,
Russell
08-26-2014 02:18 PM - edited 08-26-2014 02:22 PM
Yeah I tested to see what was going on. The weird thing was that I have access to the ACT CRM and I could see the contacts, and that they did indeed have the values inside that I was trying to retrieve.
I've since solved the issue, though. It turns out that doing:
ACTFM.Logoff();
before accessing and utilzing the properties of con, wiped out the memory that the instance of ContactList was referenced to. I'm assuming this is a security feature, so that even after legitimately accessing the data, you cannot access it unless logged in. Sigh.
Thanks for your reply though, had I still been in the dark, it would have been a breath of fresh air!