10-31-2012 03:07 PM
Hi all,
I'm trying to figure out how to create a brand new ACT contact using the SDK. I have bunch of information (First Name, Last Name, Email, Company, etc) that I pull from another system of ours, and I'm looking to push it into a new ACT contact automatically, does anyone have a quick sample of how to do this?
I tried using the Contacts.CreateContact method to create a new contact, but most of the properties are read-only...
Thanks!
Mike
11-01-2012 05:56 AM
This is something I had setup in VB.NET but I ran thru a converter for C#. It may not be formatted the greatest due to the conversion. As for a quick explanation, this block is looping through an array of datarows containing sales rep information that is being added as new contacts if that contact doesn't already exist. This was in a .NET program targeting ACT! 2012, IIRC.
foreach (DataRow dr in drs) { contList = actf.Lookups.LookupContactsNarrow(contList, dr["FullName"].ToString(), Act.Framework.Lookups.OperatorEnum.EqualTo, fdFull).GetContacts(null); if (contList.Count == 0) { //Insert Contact Act.Framework.Contacts.Contact cont = actf.Contacts.CreateContact(); cont.Fields("TBL_CONTACT.FULLNAME", Act.Framework.MutableEntities.FieldNameType.Real) = dr["FullName"].ToString(); cont.Fields("TBL_CONTACT.SALUTATION", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepSalutaton"].ToString(); cont.Fields("TBL_CONTACT.JOBTITLE", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepTitle"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_LINE1", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepAddress1"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_LINE2", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepAddress2"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_CITY", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepCity"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_STATE", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepState"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_POSTALCODE", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepZip"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_PHONE", Act.Framework.MutableEntities.FieldNameType.Real) = dr["Phone"].ToString(); cont.Fields("TBL_CONTACT.FAX_PHONE", Act.Framework.MutableEntities.FieldNameType.Real) = dr["Fax"].ToString(); cont.Fields("TBL_CONTACT.MOBILE_PHONE", Act.Framework.MutableEntities.FieldNameType.Real) = dr["Mobile"].ToString(); cont.Fields("TBL_CONTACT.BUSINESS_EMAIL", Act.Framework.MutableEntities.FieldNameType.Real) = dr["Email"].ToString(); cont.Fields("TBL_CONTACT.COMPANYNAME", Act.Framework.MutableEntities.FieldNameType.Real) = dr["RepFirmName"].ToString(); cont.Update(); intRepCount += 1; } }
I hope that helps.
11-01-2012 10:21 AM
Here is a stub of some c# code that I have that might help you. This stub looks to see if the the contents of Contact.iMIS_ID are found in the contacts and if the contact is not found it adds them. The last bit o.UpdateContacts is to bind the contact (new or exsisting) to the opurtinity (which you might not be interested in).
Hope that helps.
// prepare for our lookup by loading up critera
CriteriaColumn cSort = this.application.ActFramework.Lookups.GetCriteriaColumn("Contact.iMIS_ID", false); ;
OperatorEnum oOperator = OperatorEnum.EqualTo;
Criteria[] iCriteria = new Act.Framework.Lookups.Criteria[] { new Act.Framework.Lookups.Criteria(Act.Framework.Lookups.LogicalOperator.End, ((byte)(0)), ((byte)(0)), cSort, oOperator, myOrderBT_ID) };
// make the call to do the lookup
ContactLookup myLookup = this.application.ActFramework.Lookups.LookupContactsReplace(iCriteria, true, true);
ContactList cList = myLookup.GetContacts(null);
if (cList.Count < 1)
{
//adding new cx
myContactCommand = new SqlCommand("select * from dbo.vContacts_ACT WHERE ID = " + myOrderBT_ID, myContactConnection);
myContactReader = myContactCommand.ExecuteReader();
if (myContactReader.Read())
{
NewContact = this.application.ActFramework.Contacts.CreateContact();
NewContact.FullName = myContactReader["FIRST_NAME"].ToString() + " " + myContactReader["LAST_NAME"].ToString();
NewContact.Company = myContactReader["Company"].ToString();
NewContact.Fields["TBL_CONTACT." + fldDesciMIS.ColumnName, true] = myContactReader["ID"].ToString();
NewContact.Update();
o.UpdateContacts(new Guid[] { NewContact.ID }, null);
}
myContactReader.Close();
}
else
{
o.UpdateContacts(new Guid[] { cList[0].ID }, null);
}
11-02-2012 10:56 AM
You guys are the best, thanks again!