Eric Ho
Posts: 0
Joined: Wed Apr 02, 2014 8:55 am

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:

Image

Some guidance and help would be greatly appreciated. Thanks.

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

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

Hello,

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

Eric Ho
Posts: 0
Joined: Wed Apr 02, 2014 8:55 am

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

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 =(

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

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

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.

Eric Ho
Posts: 0
Joined: Wed Apr 02, 2014 8:55 am

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

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

Hi Eric,

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

Eric Ho
Posts: 0
Joined: Wed Apr 02, 2014 8:55 am

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

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!

Return to “Issues”