Support Forum

Ask questions and get help from MobileTogether experts.
MobileTogether Product Information
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
andy wilde  
#1 Posted : Tuesday, July 14, 2015 2:29:26 PM(UTC)
andy wilde

Rank: Newbie

Groups: Registered
Joined: 7/14/2015(UTC)
Posts: 5
United Kingdom
Location: derbyshire

Thanks: 1 times
I am new to the Mobile together platform and I'm currently evaluating the product.

My requirement is gather data from remote workers who will often have no data connection.

Do you have a worked example where the data is stsored locally on the device until there is a data connection and is then transmited to the server for permanent storage in a database?
bbv  
#2 Posted : Tuesday, July 14, 2015 4:16:31 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
Yes, this is very easy:

* You have to declare your Project with Server Access "on demand" (under Styles & Properties)
* If you have any trees which are loaded from server, you need to mark them as "Load not automatically"

This is all. I'm attaching here three mini-solutions and an accompanying SQLite database.

Solution "NewAddress" collects new user data. Note, that I'm using the $PERSISTENT tree for this - if user has to interrupt his work and close the app, he can restart the app at any time - his interim data will persist on his device. You can try it in Designer - start simulation, enter partial data, close simulation (without closing the design) and start again - you can continue with the data entry. During the data entry itself there is no contact to the server. Only if user clicks "Add to the database now" the app will contact server to transfer data - I've used a DB Execute action with an INSERT statement for this (note, there are different possibilities to save data in the DB). Then I erase data on client to prepare for the next entry.

Solution "AllAddresses" shows you all saved addresses from the same database. This solution always contacts server on purpose.

Solution "AllAddresses OnDemand" does the same as "AllAddresses", but on solution start it shows records previously loaded to the persistent tree avoiding server access. Only if user clicks the refresh button, the solution will retrieve actual data and copy it to the persistent tree for this and future displays.


Altova MobileTogether Experts
File Attachment(s):
NewAddress.mtd (7kb) downloaded 96 time(s).
AllAddresses.mtd (7kb) downloaded 92 time(s).
AllAddresses OnDemand.mtd (8kb) downloaded 95 time(s).
Addresses.sqlite (2kb) downloaded 94 time(s).
andy wilde  
#3 Posted : Tuesday, July 14, 2015 4:26:23 PM(UTC)
andy wilde

Rank: Newbie

Groups: Registered
Joined: 7/14/2015(UTC)
Posts: 5
United Kingdom
Location: derbyshire

Thanks: 1 times
thanks for such a prompt reply. I'll have a play around with the files you have sent.
andy wilde  
#4 Posted : Wednesday, July 22, 2015 9:11:51 AM(UTC)
andy wilde

Rank: Newbie

Groups: Registered
Joined: 7/14/2015(UTC)
Posts: 5
United Kingdom
Location: derbyshire

Thanks: 1 times
I've had a play around and managed to create an offline example that downloads from and updates sql and oracle databases.

However, I'm struggling with the concept of managing several records whilst offline. I see how I can persist the data for offline reading but not sure how I would update a number of records whilst offline and update the database when I next have a connection? I would also need to add new records whilst offline.

Any pointers would be most appreciated.
bbv  
#5 Posted : Wednesday, July 22, 2015 11:09:04 AM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
For editing of data, I've made a small modification to the database - I've added an autoincrement ID field. This is important to be able to identify the row you have edited.

I've also done few more changes to the previous "AllAddresses OnDemand" example. First, I've used the context menu "Create OriginalRowSet" for $DB1. With OriginalRows MobileTogether is able to generate INSERT/UPDATE/DELETE statemens for you automatically - all you do is just execute the Save command.

On data reload I'm now saving both RowSet and OriginalRowSet in $PERSISTENT tree. I've modified the table to show Edit Fields instead of Labels so that user can actually edit data. Also I've set the Table Row Group property "Automatic Append/Delete" to "true" - with this MobileTogether shows you + and - for adding rows and deleting them.

At last, I've added "Save to database" button. If your task would not require persistency of data and being able to edit without Internet connection, then everything would be very easy - you would create a dynamic table directly for $DB1 and use the Save command after user has edited it. But in your case user edits the $PERSISTENT tree. To save data to the database, I'm reloading the DB again (because it might have been changed in the meantime by other users), I'm deleting those rows from the DB RowSet which were used originally at the time of last reload. I'm appending all rows which are now available in $PERSISTENT tree. I'm executing Save command which saves the data as described above.

Due to requirement to edit data without Internet connection you have 4 actions to execute instead of 1. But this is it !!!


Altova MobileTogether Experts
File Attachment(s):
AllAddresses Persistent and Editable.mtd (11kb) downloaded 100 time(s).
Addresses2.sqlite (3kb) downloaded 95 time(s).
thanks 1 user thanked bbv for this useful post.
andy wilde on 7/22/2015(UTC)
andy wilde  
#6 Posted : Wednesday, July 22, 2015 1:06:05 PM(UTC)
andy wilde

Rank: Newbie

Groups: Registered
Joined: 7/14/2015(UTC)
Posts: 5
United Kingdom
Location: derbyshire

Thanks: 1 times
Thanks again for such a swift reply
bbv  
#7 Posted : Wednesday, July 22, 2015 2:17:35 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 476

Was thanked: 80 time(s) in 80 post(s)
One note here: in a real live scenario you will probably want to warn user from overwriting data which has been changed in the database since the last reload. I.e. imagine, you have got data 3 days ago, 2 days ago somebody else makes modifications, and today you want to save - the current implementation would simply take all records from your device and overwrite the database. Instead, you probably would want to save some kind of a timestamp in an additional field when the row has changed and use it to warn user or even prohibt him from saving data which has already been modified by another users.
andy wilde  
#8 Posted : Wednesday, July 22, 2015 4:05:23 PM(UTC)
andy wilde

Rank: Newbie

Groups: Registered
Joined: 7/14/2015(UTC)
Posts: 5
United Kingdom
Location: derbyshire

Thanks: 1 times
Yes, we have several different scenarios, I'll have to work through the logic and decide the best approach to prevent conflicts in each case.

I've got a simple solution working based on the concept you showed me in your example. I'll refine it over the next few days when other commitments allow.

I'll probably be back to pester you again when I get stuck.
Users browsing this topic
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.