How to add a field to a contact Item?

Login to reply to this topic.
Tue, 2006-01-10 03:32
Joined: 2005-07-22
Forum posts: 21
Hi guys! Can anyone show how to add a field to a contact item? I am trying to -re-assign the value of the the "job field" or just about any field. If the field has a value, I can replace it. The problem is that if the field is null, i do not know how to add it. Here is my code:

void CphonebkAppUi::ReplaceJob(){                  
                CPbkContactEngine* yellowpages= CPbkContactEngine::NewL();      
                CContactIdArray* id=yellowpages->MatchPhoneNumberL(input,11);      
                TContactItemId& contactId=(*id)[0];            
                CPbkContactItem* contact = yellowpages->OpenContactL(contactId);   
                TBuf<10> job(_L("driver"));
                TPbkContactItemField* field=contact->FindField(EPbkFieldIdJobTitle);
                if(field){
                   field->TextStorage()->SetTextL(job);            
                   yellowpages->CommitContactL(*contact);
                }
                else{
                                  this means the field is null/unused...
                                    how will I add the job field?

                                 
   }
}
         

*********
input is the phone number and lets just assume that the contactItem was found.


thanks in advance!

Tue, 2006-01-10 03:36
Joined: 2005-07-22
Forum posts: 21
Re: How to add a field to a contact Item?
just to add, i've read about  "CPbkFieldInfo &  aFieldInfo" ... but pardon me I dont know how to use it. sorry Sad
Mon, 2006-06-12 22:54
Joined: 2003-10-15
Forum posts: 78
Re: How to add a field to a contact Item?
Code:
// Create and set a non-default field
    CPbkFieldInfo* fieldInfo = engine->FieldsInfo().Find( EPbkFieldIdCountry );
    contact->AddFieldL( *fieldInfo );
    TPbkContactItemField* field = contact->FindField( EPbkFieldIdCountry );
    field->TextStorage()->SetTextL( _L("Finland") );

You can check the full compilable example also

Tue, 2006-06-13 11:02
Joined: 2006-05-09
Forum posts: 114
Re: How to add a field to a contact Item?
you can also try the Append method;
fields->AppendL(<uid of field you want to add>);
  • Login to reply to this topic.