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
Regular Contributor
davecates
Posts: 66
Registered: ‎09-10-2011
My Device: Playbook, Curve 9300, HTC Desire HD and iPhone 4

find appointment by uid doesn't work??

Hi,

 

We are creating a calendar booking system within our app.

 

When a user creates an event we store the new event's UID into a local database that we've created.

 

The list of events is then pulled in from the calendar by filtering out the events with the stored UIDs in our database.

 

Simple? Well, we seem to be able to filter on any other field of an appointment except for the UID!

 

Code example would be:

 

var apptFilter = new blackberry.find.FilterExpression("uid", "==", id);
var appt = new blackberry.pim.Appointment.find(apptFilter);

 

Where 'id' is the UIDs taken from our database.

 

appt is then the appointment we've had returned.

 

So, any ideas as to why this works for anything but the uid of an appointment?!?

 

Thanks!

Please use plain text.
Regular Contributor
davecates
Posts: 66
Registered: ‎09-10-2011
My Device: Playbook, Curve 9300, HTC Desire HD and iPhone 4

Re: find appointment by uid doesn't work??

any ideas anyone?

Please use plain text.
Retired
Tohman
Posts: 34
Registered: ‎10-24-2011
My Device: Curve

Re: find appointment by uid doesn't work??

Hi,

Small notes to the code: remove new operator from the call to Appointments’ 'find' method. Also verify type of uid is a string. Hope that helped.

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Regular Contributor
davecates
Posts: 66
Registered: ‎09-10-2011
My Device: Playbook, Curve 9300, HTC Desire HD and iPhone 4

Re: find appointment by uid doesn't work??

Hi,

Just tried it and still doesn't work.

Currently I'm having to add a custom 'fixed' note to the appointment. Search for those appointments by 'note' then matching the uid vs id by a simple if statement.

Not ideal...
Please use plain text.
Retired
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: find appointment by uid doesn't work??

I was able to get it working in the following script

        function apptUIDTest(){
            //Populate Data
            var newAppt = new blackberry.pim.Appointment();
            newAppt.location = "Your office";
            newAppt.summary = "Talk about new project";
            newAppt.freeBusy = blackberry.pim.Appointment.FREE;
            newAppt.save();  
            
            var newAppt1 = new blackberry.pim.Appointment();
            newAppt1.location = "Your office 1";
            newAppt1.summary = "Talk about new project 1";
            newAppt1.freeBusy = blackberry.pim.Appointment.FREE;
            newAppt1.save();  


            var newAppt2 = new blackberry.pim.Appointment();
            newAppt2.location = "Your office 2";
            newAppt2.summary = "Talk about new project 2";
            newAppt2.freeBusy = blackberry.pim.Appointment.FREE;
            newAppt2.save();  

            //Search
            var apptFilter = new blackberry.find.FilterExpression("uid", "==", newAppt1.uid);
            var results = blackberry.pim.Appointment.find(apptFilter);

            alert(results[0].uid === newAppt1.uid);
        }

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Regular Contributor
davecates
Posts: 66
Registered: ‎09-10-2011
My Device: Playbook, Curve 9300, HTC Desire HD and iPhone 4

Re: find appointment by uid doesn't work??

Sure, but, the appointment instance is still available in that example.

When searching via UID once the instance has been destroyed I can't get it to work.

I'm storing the UID as a string and then using that for the filter.
Please use plain text.
Retired
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: find appointment by uid doesn't work??

I can't see why search should act any different independant of the memory state, but I've created an example that uses localStorage to persist data beyond the app closing and the search functionality still works fine for me. I have attached the code.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width,target-densitydpi=device-dpi,user-scalable=no,initial-scale=1.0">
        <title> Appt UID Test </title>
    </head>
    <script>
        function populate(){
            var currentKey = localStorage.getItem("uid"),
                newAppt;

            if (!currentKey){
                alert("Creating new appointment");
                newAppt = new blackberry.pim.Appointment();
                newAppt.location = "Your office";
                newAppt.summary = "Talk about new project";
                newAppt.freeBusy = blackberry.pim.Appointment.FREE;
                newAppt.save();  
                localStorage.setItem("uid",newAppt.uid);
                newAppt = null;
            } else {
                alert("Appointment exists in localStorage");
            }    
        }

        function find(){
            var searchUID = localStorage.getItem("uid"),
                apptFilter, 
                results;

            if(!searchUID){
                alert("No Appt in localStorage");
                return null;
            } else { 
                apptFilter = new blackberry.find.FilterExpression("uid", "==", searchUID);
                results = blackberry.pim.Appointment.find(apptFilter);
                alert("Total results found: " + results.length);
                if(results.length && results[0]) {
                    alert("Results[0].uid === searchUID? - " + (results[0].uid === searchUID));
                } else {
                    alert("No results found, clearing LocalStorage key");
                    localStorage.removeItem("uid");
                }
                return results[0];
            }
        }

        
        function remove() {
            var foundAppt = find();
            if (foundAppt) {
                foundAppt.remove();
                localStorage.removeItem("uid");
                alert("Appt Deleted");
            } else {
                alert("No Appt to delete");
            }
        }
    </script>
</head>
<body>   
    <button onclick="populate();">Populate</button>
    <button onclick="find();">Search</button>
    <button onclick="remove();">Remove</button>
</body>
</html>

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Regular Contributor
davecates
Posts: 66
Registered: ‎09-10-2011
My Device: Playbook, Curve 9300, HTC Desire HD and iPhone 4

Re: find appointment by uid doesn't work??

Hi,
Thanks for your example.

Local storage only works for Playbook thought doesn't it? This app has to work via OS5+.

Anyway, we can't get it working on a search by UID.

The project is tightly under NDA but I'll re-hash the code as an example to post here shortly.

Thanks.
Please use plain text.
Retired
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: find appointment by uid doesn't work??

Acutally localstorage works on most versions of 6.0 and all of 7.0 as well. I believe simply including lawnchair and using that for persistance would make this 5.0+ compatible



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Regular Contributor
davecates
Posts: 66
Registered: ‎09-10-2011
My Device: Playbook, Curve 9300, HTC Desire HD and iPhone 4

Re: find appointment by uid doesn't work??

Ah....so we could use lawnchair instead of the database throughout the app?

All we're using the DB for is storing some text notes and references to calendar events (the IDs).

Sounds like a plan....we've found the DB so incredibly inconsistent and buggy on OS5 - just about to post some code to ask for help on it!
Please use plain text.