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

Web and WebWorks Development

Reply
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor
Accepted Solution

Add Contact OS10

[ Edited ]

Edited by oros: Moved code to code blocks for readablity.

 

Took the following sample from the API doc

 

function onSaveSuccess(contact) 
 {
    //console.log("Contact with id=" + contact.id + " is saved!");
    alert("Contact with id=" + contact.id + " is saved!");
 }

function onSaveError(error) {
   // console.log("Error saving contact: " + error.code);
   
   alert("Error saving contact: " + error.code);
}

function createContact() {
    var contacts = blackberry.pim.contacts,
        ContactField = contacts.ContactField,
        name = {},
        workPhone = { type: ContactField.WORK, value: "0046856400500" },
        workEmail = { type: ContactField.WORK, value: "ingvar@nova-data.se" },
        homeEmail = { type: ContactField.HOME, value: "ingvar.engelbrecht@gmail.com" },
        contact;
        
    name.familyName = "Engelbrecht";
    name.givenName = "Ingvar";
    contact = contacts.create({
         "displayName": "ingvar_e",
         "name": name,
         "phoneNumbers": [workPhone],
         "emails": [workEmail, homeEmail]
    });
    contact.save(onSaveSuccess, onSaveError);
}

added to config

 

    <feature id="blackberry.pim.contacts"/>
 
    <rim:permissions>  
        <rim:permit>read_geolocation</rim:permit>
        <rim:permit>access_shared</rim:permit>
        <rim:permit>access_pimdomain_contacts</rim:permit>
    </rim:permissions> 

 

got message:

 

Uncaught type error: cannot read property 'contact' from undefined

 

additional

When I first looked for information I ended up on the page below that contained no information at all but looked exactly like the normal API documentation. Please remove!

 

https://developer.blackberry.com/html5/apis/blackberry.pim.contact.html

 

 

 

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Add Contact OS10

Can you confirm which line of code is throwing that error?

 

Based on the wording, I would expect something along the lines of someVariable.contact to be throwing the error, but I can not see any such usage in the posted code.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Add Contact OS10

The error message in the ripple log is underneath this statement

 

var contacts = blackberry.pim.contacts,
If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Add Contact OS10

[ Edited ]

Is this issue happening on the device or within Ripple? If Ripple, please note that blackberry.pim is not actually defined / available there.

 

BB10 Documentation: https://developer.blackberry.com/html5/apis/blackberry.pim.contacts.contact.html

 

EDIT: Note that your documentation link is for the BBOS PIM APIs: https://developer.blackberry.com/html5/apis/blackberry.pim.contact.html

 

You will need to test on a Simulator / physical device. If this is not in Ripple, if you execute the following three lines of code prior to the identified error line, can you please confirm the output?

 

console.log(blackberry);
console.log(blackberry.pim);
console.log(blackberry.pim.contacts);

I am expecting that you will get:

1) An object.

2) undefind.

3) An error thrown simliar to the original.

 

If that's the case, the issue will be stemming from how the API is being included (and I'll have a few more questions.)


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Add Contact OS10

Its ripple.

will test on simulator when I have got the unzip working on the simulator.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.