How do I pass a row into the database using Create_Service.execute?
I have been struggling with offline data synchronization to the database for my customer data management app. I have followed the ToDo offline tutorial on Appery and I am building the app based on the script provided there.
Instead of the only saving taskname, i need to sync clientname, phone, email, and product into the database when the device goes online.
There is no problem loading these values to DB when online. I could see the local storage variables stored correctly but somehow it is not updating the database when device returns to online status. I have read through your tutorials on database, and REST and searched the forum here. Nothing is working for me.
I suspect the problem is in startSynchronization() function:
// Creating
tasks = localStorage.getItem('_tasksToCreate');
if (tasks) {
var tasksArr = eval('(' + tasks + ')');
Code: Select all
while (tasksArr.length) {
task = tasksArr.shift();
if (task.name) {
create_service.execute({
data: {
name: task.name,
email: task.email,
phone: task.phone,
product: task.product
}
});
}
}
localStorage.setItem('_tasksToCreate', '');
} my createServiceExecute function:
// Create service execute
function createServiceExecute() {
var isOnline = localStorage.getItem('_isOnline');
Code: Select all
var newClient = new Object();
newClient.name = localStorage.getItem('_clientName');
newClient.phone = localStorage.getItem('_phone');
newClient.email = localStorage.getItem('_email');
newClient.product = localStorage.getItem('_product');
if (newClient.name && newClient.name.trim()) {
if (isOnline == 1) {
create_service.execute({});
} else {
addTaskToCreate(newClient.name, newClient.phone, newClient.email, newClient.product);
var tmpEcho = localStorage.getItem('_echo');
tmpEcho = eval('(' + tmpEcho + ')') || [];
tmpEcho = addTaskToLocalList(newClient.name, newClient.phone, newClient.email, newClient.product, tmpEcho);
tmpEcho = JSON.stringify(tmpEcho);
localStorage.setItem('_echo', tmpEcho);
//startSynchronization();
listServiceExecute();
}
} }
and here's a screenshot of the local storage vars during runtime:
Some guidance and help would be greatly appreciated. Thanks.