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
Highlighted
Visitor
Posts: 1
Registered: ‎02-24-2012
My Device: Bold 9700
My Carrier: Telus

Email Message Search

I've searched for find() examples without success. I'm new to webworks & I'm having trouble getting started with the find() function.

My goal is to search the Inbox for a specific string in the subject line and use the results in my app.

Any help would be appreciated.

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Email Message Search

Looking in the API reference guide (https://bdsc.webapps.blackberry.com/html5/apis/blackberry.message.Message.html#.find) I can confirm we don't have a code snippet for this.  We should.  

 

So I've just added this issue to the Docs repo in Github : https://github.com/blackberry/WebWorks-API-Docs/issues/300

 

In the meantime, this snippet may help you to get started:

 

var filter, sender = "test@email.com", msgs, i, results = [];

//Finds (max 100) emails from a specific email address
filter = new blackberry.find.FilterExpression("from", "==", sender);
msgs = blackberry.message.Message.find(filter, 100);

for (i = 0; i < msgs.length; i = i + 1) {
	
	if (msgs[i].status === blackberry.message.PRIORITY_HIGH) {
		results.push(msgs[i]);
	}
}

alert("Found " + results.length + " high priority emails from " + sender);

 

 

One best practice that deserves some mention, is that if you constantly use the find() method to query the inbox, you are going to notice your app will be very slow.  Its better to get a list of results once and save it locally, and then search through that list. For example, get a broad list of results as part of the onLoad event and save it in memory (global JS variable perhaps). Then loop through that list when you need to find/display something.

 

 

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Developer
Posts: 64
Registered: ‎02-12-2011
My Device: 9300
My Carrier: Yoigo

Re: Email Message Search

Hi all.
I'm not able to see the documentation. I'm getting php errors precisely on the API related with emails (Message and Filter).
Developer
Posts: 64
Registered: ‎02-12-2011
My Device: 9300
My Carrier: Yoigo

Re: Email Message Search

The documentation is back now and with many examples. Thanks.

 

I was wondering... where can I see all possible fields for a FilterExpression of emails? I've seen "from" in this example. I assume "to", "body" and "subject" are the others... is there more?

 

Cheers.