Page 1 of 1

How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 8:55 am
by Eric Ho

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:

Image

Some guidance and help would be greatly appreciated. Thanks.


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 11:22 am
by Nikita

Hello,

Did you finish successfully the original tutorial:
http://docs.appery.io/tutorials/build... ?


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 11:28 am
by Eric Ho

Yes but the tutorial does not seem to work in browser mode (I am using chrome) i have followed your tutorial closely. have been struggling with this problem for 3 days. Please help =(


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 11:50 am
by Nikita

In this tutorial device events are used. So you can't completely test it on the desktop. You should install your app and test on it. It's better to finish the original tutorial at first, it'll prevent most of the errors.


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 12:00 pm
by Eric Ho

Thanks for your reply. I have finished the tutorial and installed tester app from appery. I have tried everything and didn't have a single clue on what is wrong before asking on this forum =(

i have tried this from a user having similar problem here: https://getsatisfaction.com/apperyio/...

but it didnt work for me


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 1:17 pm
by Kateryna Grynko

Hi Eric,

Appery.io Tester won't work with device events, this has to be tested on installed .apk or .ipa.


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 1:38 pm
by Eric Ho

Hi Katya,

Thanks for your reply. I have tried with .apk on my phone but problem still exists. I just want to know if my code provided above is correct or not? Your answer is greatly appreciated ! =)

Thanks!


How do I pass a row into the database using Create_Service.execute?

Posted: Wed Apr 02, 2014 2:06 pm
by Kateryna Grynko

Hi Eric,

Try debugging with Weinre please: http://docs.appery.io/documentation/d...