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

Adding contact

After learning that ripple does not support the contact API I have tried the simulator.

 

config has:

 

    <feature id='blackberry.pim.contacts' required='true' version='1.0.0.0'/>
    <rim:smileytongue:ermissions>
       <rim:smileytongue:ermit>access_pimdomain_contacts</rim:smileytongue:ermit>
    </rim:smileytongue:ermissions>

 

2 slightly different routines.  None of them triggers success nor error. One from API doc, the other one from somewhere else, forgot.

 

------- snip -----------------  
            
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()
  {
    'use strict';
   //alert("enter 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);
}

 

------------  snip  ---------------

 

function saveContact() {
'use strict';
var options, contact, onSuccess, onError;
alert("Enter savecontact");
/* Our fields to set for this contact. */
options = {};
options.name = new blackberry.pim.contacts.ContactName();
options.name.givenName = document.querySelector('Ingvar').value;
options.name.familyName = document.querySelector('Engelbrecht').value;
options.nickname = document.querySelector('ingvar_e').value;

/* Create a new contact based on our options. */
contact = blackberry.pim.contacts.create(options);

/* If creation succeeds, let the user know. */
onSuccess = function (contact) {
alert('Contact (ID: ' + contact.id + ') successfully saved.');
};

/* If there is an error, let the user know. */
onError = function (error) {
alert('Error ' + error.code);
};

/* Call the blackberry.pim.contacts.Contact.save function with our trigger functions. */
contact.save(onSuccess, onError);
}

-----------------  snip   ------------------

 

Hofstaedters law:

 

Everything takes longer than planned even if you take Hostaedters Law into consideration

 

Recursion

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Retired
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Adding contact

I'd recommend using this learning resources as a guideline for how to support Contacts feature in your WebWorks application:

 

https://github.com/blackberry/BB10-WebWorks-Community-Samples/tree/master/pimcontacts

 

 

Are you seeing any runtime errors in calls to blackberry.* APIs?  If so the webworksready event may not be fired yet.  Otherwise

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700

Re: Adding contact

Thanks Astanley,

The second code snippet in my original posting is from the Github sample you recommended.

 

There are no error messages.  I have started to setup debug but that is a process by itself. I got the signing keys using my original request for keys in OS5 but I do not see any possibillity to get the debug tokens that way so I have to start all over and submit a new request

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700

Re: Adding contact

[ Edited ]

I have this code for webworksready in my index

 

<script type="text/javascript" charset="utf-8">

var pb = false;
function onLoad() {
   document.addEventListener("webworksready", onWebworksReady, false);
}
function onWebworksReady() {
   blackberry.event.addEventListener("pause", onPause);
   startapp();
}
function onPause() {
}
    var meta = document.createElement("meta");
    meta.setAttribute('name','viewport');
    meta.setAttribute('content','initial-scale='+ (1/window.devicePixelRatio) + ',user-scalable=no');
    document.getElementsByTagName('head')[0].appendChild(meta);
</script>

 

I get no error messages whatsoever when running the two variations above

 

It seems that the Contacts is not supported on the VMWare simulator either.  Behaves identical to the ripple simulator. Nothing happens. code seems to stop when reaching statements refering to contact

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700

Re: Adding contact

Can anyone verify that Adding a contact works with the VMWare simulator?

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700

Re: Adding contact

It does  not seem to be a problem with the VMWare simulator. I run the "Cascades" sample and it works just fine.

 

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700

Re: Adding contact

Forgot to add.

None of the two samples for webworks I mentioned initailly works. Just nothing happens. No error exit, no OK exit. Nada.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-