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
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4
Accepted Solution

ReferenceError: Can't find variable: blackberry

When I try to run this code:

 

blackberry.pim.contacts.find(contactFields, null, onFindSuccess, onFindError);

 on device I got error in Web Inspector:

ReferenceError: Can't find variable: blackberry

 

Could anyone help me?

 

Thanks in advance

All time online :smileyvery-happy:
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ReferenceError: Can't find variable: blackberry

Add <feature id="blackberry.pim.contacts" /> in your config.xml

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: ReferenceError: Can't find variable: blackberry

My config.xml contains:

 

<rim:permissions>
		<rim:permit>access_pimdomain_contacts</rim:permit>
</rim:permissions>

<!-- Additional features. -->
<feature id="blackberry.pim.contacts" />

 

All time online :smileyvery-happy:
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ReferenceError: Can't find variable: blackberry

At first you need to wait the webworks.js is loaded. Do what you want in the ready function :

 

function ready() {

    var ele = document.createElement("div");
    ele.innerHTML = "uuid: " + blackberry.identity.uuid;
    document.documentElement.appendChild(ele);
}
window.addEventListener("load", function(e) {
    document.addEventListener("webworksready", ready);
}, false);
Twitter : @LaurentKP
My apps
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: ReferenceError: Can't find variable: blackberry

I don't know why, bu tyour code don't work...
All time online :smileyvery-happy:
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ReferenceError: Can't find variable: blackberry

It's part of the helloworld example from the BB getting started documentation. It should work.

https://developer.blackberry.com/html5/documentation/creating_a_bb10_app_2007539_11.html

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: ReferenceError: Can't find variable: blackberry

I have code:

setTimeout(function() { moreConSim(); }, 500);
	
function ready() {
	alert('now');
	alert(blackberry.identity.uuid);
}
window.addEventListener('load', function(e) {
	alert('ok');
	document.addEventListener('webworksready', ready);
}, false);

Function moreConSim() runs and alerts from ready() and function(e) don't...

 

But on Ripple emulator in console, I can see, that "webworks.bb10 :: fired webworksready event!"

All time online :smileyvery-happy:
Please use plain text.
Developer
interfaSys
Posts: 817
Registered: ‎11-19-2009
My Device: Z10, Q10, 9900, 9790, PlayBook,
My Carrier: T-Mobile UK, Three, O2, Orange, Sunrise, Swisscom

Re: ReferenceError: Can't find variable: blackberry

[ Edited ]

Ripple fires the event, but you need to make sure to wait for it before calling blackberry.something.

 

moreConSim() should be called from within your ready() function if moreConSim() is where you have blackberry.pim.contacts.find(contactFields, null, onFindSuccess, onFindError);

 

--
Olivier - interfaSys ltd
Developing for BlackBerry 10 devices using the Sencha Touch framework.
Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 614
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: ReferenceError: Can't find variable: blackberry

Feel free to use our samples for reference to.  Here's how I add the event listener to my samples:

 

https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/Accelerometer-Fight/index.html#L41-L...

 

But yes, you're either not waiting for the webworks ready event before calling a blackberry API, or you're not including the webworks sdk properly in your app.  You can see an example of that also, over here: https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/Accelerometer-Fight/index.html#L33

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Developer
26filip
Posts: 224
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: ReferenceError: Can't find variable: blackberry

Thank you, @chadtatro! I'm developing my 6th application in WebWorks for BB10, but first using API.

 

The issue was because of no included framework JS :smileyhappy:

All time online :smileyvery-happy:
Please use plain text.