Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
flvl
Posts: 2
Registered: ‎06-02-2011
My Device: 9300

Why isn't company field updated (refreshed) after changing it from code?

Hi all,

I've got a question regarding blackberry pim list. So, I have the following code :



public void openContact () throws PIMException {
    appendInfo("Start info!");
    BlackBerryContactList contactsList = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
    if (contactsList==null){
        appendInfo("There are no contacts!");
        return;
    }  
    appendInfo("We have :");
    appendInfo(new Integer(contactsList.size()).toString());


    Enumeration enumx = contactsList.items();
    while (enumx.hasMoreElements()) {
        BlackBerryContact c = (BlackBerryContact) enumx.nextElement();

        String[] contact =  new String[2];


        if (contactsList.isSupportedField(BlackBerryContact.NAME)) {
            String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
            String firstName = name[Contact.NAME_GIVEN];
            String lastName = name[Contact.NAME_FAMILY];
            contact[0] = firstName + " " + lastName;
        }
        if (contactsList.isSupportedField(BlackBerryContact.ORG)) {
            c.setString(BlackBerryContact.ORG, 0, BlackBerryContact.STRING, "NewCompany");
            StringBuffer orgs = new StringBuffer();
            int orgCount = c.countValues(BlackBerryContact.ORG);
            for (int i = 0; i < orgCount; i++) {
                String org = c.getString(BlackBerryContact.ORG, i);
                if (org != null) {
                    orgs.append(org.trim());
                    orgs.append("; ");
                }
            }
            contact[1] = orgs.toString();
        }

        appendInfo(contact[0]+ " works at "+contact[1]);
    }
}

 

this code successfully changes the value of the field company for all contacts on the phone (beware) to "NewCompany".

 

The problem is that after I run this code, and I call a person from my phone's agenda that person's old company is displayed on the outgoing screen, and not the new company. The same thing happens for an incoming call (also for the phone's contact list). The only way I can see that the company field has changed is to try to edit a contact, and only there I can see that the value of the company field is "NewCompany".

 

I've restarted the phone hoping that there is a cache that needs to be rebuild, but that didn't fixed the problem.

 

Does anyone have any idea why this is happening? How can i fix this? It is possible?



Thanks.

New Contributor
flvl
Posts: 2
Registered: ‎06-02-2011
My Device: 9300

Re: Why isn't company field updated (refreshed) after changing it from code?

I've found what i was doing wrong, i/ve forgot to call commit() on the changed contact.

        ...
        contact[1] = orgs.toString();
            c.commit();
        }

        appendInfo(contact[0]+ " works at "+contact[1]);
        ...