Community
Showing results for 
Search instead for 
Do you mean 
Reply

programatically inserted contacts have wrong phone country codes

New Member
Posts: 5
Country: Philippines

programatically inserted contacts have wrong phone country codes

We're using ACT! Professional 8.0 Version 8.0.2.82, English (United Kingdom) and we're inserting contacts using c# 2.0. Below is a glimpse of our insert contact code:

 

Contact NewContact;

NewContact = afw.Contacts.CreateContact();

NewContact.Company = lead.Company;

NewContact.FullName = lead.Name;

 

NewContact.Fields[
"TBL_CONTACT.BUSINESS_COUNTRYNAME", true] = lead.Country;

NewContact.Fields["TBL_CONTACT.HOME_COUNTRYNAME", true] = lead.Country;NewContact.Fields[

"TBL_CONTACT.BUSINESS_PHONE", true] = lead.WorkPhone;

NewContact.Fields["TBL_CONTACT.BUSINESS_POSTALCODE", true] = lead.PostCode;NewContact.Fields[

"TBL_CONTACT.HOME_PHONE", true] = lead.Phone;

NewContact.Fields["TBL_CONTACT.FULLNAME", true] = lead.Name;NewContact.Fields[

"TBL_CONTACT.BUSINESS_STATE", true] = lead.County;

 

NewContact.Fields[
"TBL_CONTACT.COMPANYNAME", true] = lead.Company;

NewContact.Fields["TBL_CONTACT.BUSINESS_CITY", true] = lead.City;NewContact.Fields[

"TBL_CONTACT.BUSINESS_LINE3", true] = lead.Address3;

NewContact.Fields["TBL_CONTACT.BUSINESS_LINE2", true] = lead.Address2;NewContact.Fields[

"TBL_CONTACT.BUSINESS_EMAIL", true] = lead.Email;NewContact.Fields["TBL_CONTACT.BUSINESS_LINE1", true] = lead.Address1;

 

NewContact.Fields["TBL_CONTACT.MOBILE_PHONE", true] = lead.Mobile;

 

// update the contact

NewContact.Update();

 

Everything is fine here... until we see the Phone field value.

 

Unlike a contact manually created straight from ACT!, the Phone Number would automatically get a "[1]" prefix for US country code (even when the Contact's Country is set to United Kingdom). We've also tried iterating through afw.PhoneManager.GetAllMasks() and set parameters 'IsActive' and 'Default' values to 'false' for all non-UK masks prior to Contact creation but it didn't work as well.

 

We've read the one and only post with a similar problem (http://community.act.com/sage/board/message?board.id=Pub_Dev&message.id=415) and one of the suggestions is to add "0044" to the phone number string. Didn't work as well. it produced "[1]0044########". 

 

LOL out of sheer desparation, we even tried:  

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-GB");

 

and of course, it didn't work.

 

Any help would be deeply appreciated. Thank you in advance!

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: programatically inserted contacts have wrong phone country codes

[ Edited ]

Hi pcgutierrez,

 

I think the following may work. I haven't tried it out on intellisense or VS and is very rough and also in C# but hopefully it will be usefull: (Edit: Doh! just realised you had posted up in c# anyway...hmmm will write a hundred times on balckboard "I must learn to read posts in full and properly in the future!" Hahaha!)

 

PhoneManager pMan = afw.PhoneManager;
PhoneNumber pNum = pMan.GetPhoneNumberFromString(NewContact.Fields["TBL_CONTACT.HOME_PHONE", true].toString(),NewContact);

pNum.CountryCode = pMan.GetCountryCodeFromCountry("United Kingdom" ) ;

NewContact.Update();

 

Basically we need to get the PhoneManager and from the PhoneManager get the relevent PhoneNumber object for our contact. Once we have that we can then set the Country property to our preferred value. There is also a method in the pMan that gets a Set of all the Country objects in the dB so you can itterate through and get the correct string if "United Kingdom" is incorrect.

 

HTH

Vivek

Message Edited by vivek on 09-10-2008 10:29 AM
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
New Member
Posts: 5
Country: Philippines

Re: programatically inserted contacts have wrong phone country codes

Hi vivek,

 

I've tried the following codes and it didn't work:

 

PhoneNumber pNum = afw.PhoneManager.GetPhoneNumberFromString(NewContact.Fields["TBL_CONTACT.BUSINESS_PHONE", true].ToString(), NewContact);pNum.CountryCode = afw.PhoneManager.GetCountryCodeFromCountry("United Kingdom");

NewContact.Update();

 

I even tried the one below and had the same result:

 

PhoneNumber pNum = afw.PhoneManager.GetPhoneNumberFromString(NewContact.Fields["TBL_CONTACT.BUSINESS_PHONE", true].ToString(), NewContact);

pNum.CountryCode = afw.PhoneManager.GetCountryCodeFromCountry("United Kingdom");pNum.FormattedNumber =

"[" + pNum.CountryCode + "]" + pNum.RawNumber;

NewContact.Update();

 

I also noticed something strange. If I were to retreive the created contact programatically at a later time, the value of Contact.Fields["TBL_CONTACT.BUSINESS_PHONE", true].ToString() does not contain the "[1]" or any country code prefix. I'm about to pull all my hair out LOL!

 

Nonetheless, thanks for trying. Smiley Happy

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: programatically inserted contacts have wrong phone country codes

Hi pc,

 

Ok I decided to run it on VS and here it is:

 

Contact cont = oFram.Contacts.GetMyRecord();

PhoneNumber pNum = oFram.PhoneManager.GetPhoneNumberFromString(oFram.Fields.GetFields(RecordType.Contact)["Phone"].ToString(), cont);listBox1.Items.Add(

"Old Country Code: "+pNum.CountryCode.ToString());

pNum.CountryCode = oFram.PhoneManager.GetCountryCodeFromCountry("United Kingdom");

listBox1.Items.Add("New Country Code: " + pNum.CountryCode.ToString());

 

oFram in my code = afw in yours.

The reason why the previous rough code I wrote didn't work was me being stupid! Sorry! I used the Contact object that was possibly in a dirty state since we were reading the field list from it. This time however if you notice we get the field from the ActFramework object and pass the Display Name of the field in as oppose to the collumn name.

 

HTH

Vivek

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Nickel Super Contributor
Posts: 352
Country: Canada

Re: programatically inserted contacts have wrong phone country codes

Vivek,

 

I saw this post and am working through an issue with phone numbers as well, and think I can apply this to phone number masking as well, which is great!  But, my question is how do you write the updated phone object back to the DB after the country code (or mask) is set?

 

Thanks,

Len

Len Kamerman
ACT! Certified Consultant

Act E-mail Marketing Trainining Course:

http://actsoftware.training
New Member
Posts: 5
Country: Philippines

Re: programatically inserted contacts have wrong phone country codes

Hi vivek,

 

I've tried the following codes and still had the same result with the [1] persisting:

 

//Perform Lookup

 CriteriaColumn cColumn1, cColumn2, cColumn3;

OperatorEnum oOperator1;

string sValue1, sValue2, sValue3;

ContactLookup cLookup;

ContactList cList;

//initialize some varables

oOperator1 = OperatorEnum.EqualTo;

sValue1 = lead.Email;

 

//Get the column(s) to lookup on

cColumn1 = afw.Lookups.GetCriteriaColumn("TBL_CONTACT", "BUSINESS_EMAIL", true);

cColumn2 = afw.Lookups.GetCriteriaColumn("TBL_CONTACT", "PERSONAL_EMAIL", true);

//Create an array to hold all of the lookup criteria

 Criteria[] lCriteria = new Criteria[] {new Criteria(LogicalOperator.Or, (byte)0, (byte)0, cColumn1, oOperator1, sValue1),

new Criteria(LogicalOperator.End, (byte)0, (byte)0, cColumn2, oOperator1, sValue1),

//new Criteria(LogicalOperator.End, (byte)0, (byte)0, cColumn1, oOperator1, sValue3)

};

//Create the Lookup

cLookup = afw.Lookups.LookupContactsReplace(lCriteria, true, true);

//Set our contact list to the lookup

 ContactFieldDescriptor cfd1 = afw.Contacts.GetContactFieldDescriptor("TBL_CONTACT.CREATEDATE", true); SortCriteria[] sort = new SortCriteria[] { new SortCriteria(cfd1, System.ComponentModel.ListSortDirection.Descending) };

 

cList = cLookup.GetContacts(sort);

 

//get the first lookup result

 

Contact cont = cList[0];

 

PhoneNumber pNum = afw.PhoneManager.GetPhoneNumberFromString(afw.Fields.GetFields(RecordType.Contact)["Phone"].ToString(), cont);

pNum.CountryCode = afw.PhoneManager.GetCountryCodeFromCountry("United Kingdom");

cont.Update();

 

With your original codes, I also attempted to alter the country code of the oFram.Contacts.GetMyRecord() contacts into something else. Sadly, looking at the record using the ACT! client UI doesn't seem to have been changed at all.  

 

What's strange is that the pNum.CountryCode initial value is already 44 before the codes above even changed it. Here are the initial values of all the pNum properties from the run-time debugging immediate window:

 

pNum

{Act.Framework.Database.FieldDescriptor}

CountryCode: 44

FormattedNumber: "Act.Framework.Database.FieldDescriptor"

Mask: {Act.Framework.Phones.Mask}

RawNumber: "ActFrameworkDatabaseFieldDescriptor"

 

I'm not sure why, but the value for both raw amd formatted numbers is the string "ActFrameworkDatabaseFieldDescriptor."

 

Any ideas as to where it went wrong?

 

Thanks for taking the time to test it out in VS. <3

Platinum Elite Contributor
Posts: 14,384
Country: Australia

Re: programatically inserted contacts have wrong phone country codes

For info... ACT! 8.0 had an issue adding correct country codes programatically. Even ACT! for Web and Create Contact from Outlook couldn't do it.

 

They would display in the format ok, but the field would always show US... and that doesn't make dialing/etc easy when I'm in Australia.

 

Here's a shot I took with 9.0 - see what's wrong? And you can't just change it...

 

 

Phone issue 

 

The only fix for a phone added from Outlook or Web (or any other code) was to erase the field (or Ctrl-X), save the record and re-add the number

 

I posted it many times, but don't think the US guys understood.  I don't think it was fixed till I finally got hold of Ben in the US after 10.0 was released. Fixed in 10.01

New Member
Posts: 5
Country: Philippines

Re: programatically inserted contacts have wrong phone country codes

Hi Mike,

 

Thanks for the reply and for saving me from hours of hopeless mind-numbing problem-solving LOL! Smiley Happy Please correct me if I'm wrong, this problem would mess with any automated dialing application, right (or is it just a Display issue)?

 

Wish they just made whatever mechanism that determines the default country code simple and based the country code value on the contact's Country field --and sure throw that "[1]" in there if Country field is empty.

 

 

Platinum Elite Contributor
Posts: 14,384
Country: Australia

Re: programatically inserted contacts have wrong phone country codes

Glad the work I did a couple of years ago was useful to someone...
I would think it would mess with dialing software... not sure why the Phone Format box shows it correctly.

Throw the user's the My Record's phone cc, not [1] - but that's not the real issue as the Format Box does have the correct data

You can test it by adding a contact from Outlook using ACT!'s own code - and same with ACT! for Web.

Only solution - upgrade to ACT! 2008 or 2009

Here's some additional info on the ACT! 2005/2006 phone issue from my logs - maybe helpful to you:

This is the result of my research of PhoneNumbers in ACT:

We can retrieve the country code, ormatting mask and the real number using Phone Number and honeNumberFieldDescriptor classes form ACT SDK. But to maintain consistency, his same information( real number, formatted number, formatting mask,
country code) must be kept on the handheld and synced back to the plugin to reate proper PhoneNumber object, otherwise ACT will not recognize the upplied phone number and it will add “1”  before the number assuming hat this is US phone number.

This is snippet from ACT SDK that describes the constructor of the PhoneNumber class

[Visual Basic]
Public Function New( _
ByVal formattedNumber As String, _
ByVal rawNumber As String, _
ByVal mask As Mask, _
ByVal CountryCode As Integer _
)

 

                      Act 2005 Standard         Act! 2006 Standard                   Act! 2006 Premium

1. Select country 'Australia', keep default phone number             

Act!               [61] 3142341234                      [61] 3142341234                   3142341234

XML             3142341234                               3142341234                          3142341234

2.Select country 'Australia', change to 'free format', enter full number

Act!               [61] 3142341234                      [61] 3142341234                   3142341234

XML             3142341234                               3142341234                          3142341234

3. Select country 'Australia', create your own format of 61 (%%%) %%%%

Act!              [61] 61(314)2341234               [61] 61(314)2341234             61(314)2341234

XML             61(314)2341234                        61(314)2341234                   61(314)2341234

 

Obviously 3 is pretty useless

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: programatically inserted contacts have wrong phone country codes

Hi pc, ilk and Mike,

 

First appologies for some errors I made in my code. The snippet: oFram.Fields.GetFields(RecordType.Contact)["Phone"].ToString() would always just return the value of Act.Framework.Database.FieldDescriptor since the snippett is returning the object not the value...sorry Doh!

 

Anyway after ilk's post I naively presumed all we would need to do would be a simple NewContact.Update() and the Framework would resolve the object calls etc but I was sadly wrong! Bummer! Then Mike's post made me think and after a little delving with Reflector found that the Act.Framework assembly only makes a single call once to the PhoneNumber Object namely: Act.Framework.ActDatabase.ActDatabaseManager.AssimilateContact(Contact&,Contact,ActFramework) which is a protected method anyway! So my (guessed) conclusion is that using the Act.Framework.Phone assembly we can't commit changes to properties like country and mask via the Framework (I haven't looked into the UI elements yet).

After reading Mike's post I decided to try seeing if we alter the country value for the business_Country field would that update the Country property of the phonenumber and it does some how! Here is my messy testing code:

 

Contact cont = oFram.Contacts.GetMyRecord();

var f = from fd in oFram.Contacts.GetFieldDescriptors()

where fd.DisplayName == "Phone"

 select fd;

PhoneNumber pNum = new PhoneNumber(String.Empty, string.Empty, new Mask(), oFram.PhoneManager.GetCountryCodeFromCountry("United Kingdom"));

foreach (DBFieldDescriptor dbf in f)

{

pNum = oFram.PhoneManager.GetPhoneNumberFromString(dbf.GetValue(cont).ToString(),cont);

}

var fCountry = from fd in oFram.Contacts.GetFieldDescriptors()

where fd.DisplayName == "Country"

 select fd; foreach (DBFieldDescriptor dbf in fCountry)

{

listBox1.Items.Add(dbf.GetValue(cont).ToString());

dbf.SetValue(cont,
"United Kingdom");

cont.Update();

}

listBox1.Items.Add(
"Old Country Code: "+pNum.CountryCode.ToString());listBox1.Items.Add("Old RawNumber: " + pNum.RawNumber);

listBox1.Refresh();

pNum.CountryCode = oFram.PhoneManager.GetCountryCodeFromCountry("United Kingdom");pNum.RawNumber =

"0122444444";

 

cont.Update();

listBox1.Items.Add(
"New Country Code: " + pNum.CountryCode.ToString());

listBox1.Items.Add("New RawNumber: " + pNum.RawNumber);

 

As you can see after running the dbf.SetValue() and then Update() the pNum.CountryCode shows the correct code. So this solves the CountryCode issue but I have no idea how to deal with the masks unfortunately. This is an interesting problem and I hope I am missing some really obvious point somewhere!

 

Vivek

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog