12-21-2011 12:21 PM
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!
12-22-2011 08:17 AM
any ideas anyone?
12-22-2011 04:31 PM
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.
button below the post(s)
12-22-2011 07:13 PM
12-22-2011 09:01 PM
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);
}
button below the post(s)12-22-2011 09:08 PM
12-23-2011 11:20 AM
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=devi ce-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>
button below the post(s)01-13-2012 06:31 PM
01-16-2012 11:12 AM
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
button below the post(s)01-17-2012 07:05 AM