How to call multiple Zync steps from within one script?

Help, Tips, and Tricks for deploying GoZync: our "sync" engine for FileMaker Go.
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Fri Sep 13, 2013 9:23 am
Within my solution, I have a button that I want to use to check for a new version of the current file AND a separate file that is linked to it via an External Data Source. In the most basic instance, this script just contains these two steps:
Code: Select all
Perform Script ["Zync - Check For Updates"]
Perform Script ["Zync - Check For Updates" from file: "Backend"]

The problem is that the second script step never runs. I think I understand if the second step doesn't run if there is an update in the first script (because the entire file is closed at the end?), but why wouldn't the second step run if there were no updates in the first step?
SeedCode Staff
SeedCode Staff
Posts: 2764
Joined: Thu Nov 20, 2003 11:01 am
PostPosted: Fri Sep 13, 2013 11:16 am
Hi Aaron,

Am I understanding correctly that you'd like one script to test and possibly download more than 1 file if it's in need of updating? We don't currently support that. We've made the updating of new file versions as easy as we can--in FileMaker, anyway--but having one routine that just does them all currently isn't doable in GoZync. Users will need to click "check for updates" within each file being updated. (Note that doing this check from within *your* mobile file checks for unsynced data before delivering the new version. Running the check straight from GoZync mobile does not.)

So to put it in App Store terms, you can update individual files, but can't "update all". Sadly you don't do other things while you're updating either, as you can in the App Store. That's on my wish list also. =)

Hope that helps,

John
John Sindelar
SeedCode
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Fri Sep 13, 2013 11:22 am
Yes, you understand correctly. I'll have to think of some workaround. My users don't directly access any backend files(and if they do, are just presented with a plain layout stating that they opened up the wrong file). All access to any database files beyond the main one is done through 'External Data Source' linkage, but obviously there will exist a time when a backend file will need a new version. With my end user base, I need to make updates as dead simple as possible.
SeedCode Staff
SeedCode Staff
Posts: 2764
Joined: Thu Nov 20, 2003 11:01 am
PostPosted: Fri Sep 13, 2013 11:40 am
It won't be a problem to call a script in any one backend file to check for updates; you'll just have to do it one at a time, which can be a pain. Maybe create a little ui for them showing a list of the X backend files and the date/time last checked for updates with a green check mark if it's up to date and within Y days of today. Then they would just need to click "update" next to each row until they all have green checkmarks. ??
John Sindelar
SeedCode
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Fri Sep 13, 2013 1:09 pm
That is a pretty good idea for a workaround. Will attempt after the weekend!
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Mon Sep 16, 2013 12:26 pm
When attempting this, I am getting the "file locked" error that I thought was fixed with one of the newer versions of GoZync.

Within my main file, I have a button to check for an updated version of my backend file. The button setup:
Code: Select all
Perform Script ["Zync - Check For Updates" from file: "Backend"]

Running this correctly gives me the "There is a new version of "Backend.fmp12" available. Do you want to install it?" prompt. But everytime I select Install I get the "This file is locked or in use." Error. When I select OK, my backend file is open and in the fore-front, even though it wasn't open when I ran the script.
SeedCode Staff
SeedCode Staff
Posts: 475
Joined: Wed Jan 02, 2013 11:47 am
PostPosted: Mon Sep 16, 2013 12:55 pm
Hi Aaron. I'm not sure why that wouldn't work. Have you tried running the "Zync - Check For Updates" script directly from the Backend file (rather than from your Main file)? Let me know if that makes a difference.
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Mon Sep 16, 2013 1:42 pm
If I run the Update script directly from the Backend file, it will error if the main file is open, but it will work if the Backend file is the only file open.

Just in case this might have to do with me trying to implement your proposed workaround, which involves me setting a date field from within the Update script, I tried this again with a different backend file (my solution has a total of 3 of them) that wasn't modified at all, and I get the same ERROR if trying to call the script externally from my main file.
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Tue Sep 17, 2013 12:21 pm
Any ideas what to check next? I need my users to update the versions of the solution's linked files from one user-friendly interface within the main file. They can't (and won't) go into the backend files directly to update.
Posts: 18
Joined: Thu Oct 11, 2012 8:03 am
PostPosted: Mon Sep 23, 2013 10:40 am
Got it working! Can now update backend files from within the primary database.

First, here is the crux of the problem, as Seed Code explained it to me (paraphrasing your words here Jeff):
You're using the separation model in your mobile solution, and you're running the "Check for Updates" script in the backend data file, but initiating it from the main UI file. The reason you're getting the "file is locked" error message when you try to install an updated version of your backend file is that the UI file is forcing that file to stay open. Try it on your desktop. You can't close the backend file. I guess you could say GoZync wasn't designed to support the separation model in the mobile solution.

To do what you want to do, you'd have to explicitly close the UI file at some point in the update process, so that when GoZync closes the data file it's trying to replace, that file stays closed. Maybe a subscript toward the beginning of the "Check for Updates" script in each data file that closes the UI file before it proceeds?


So it took a number of steps to work around this--don't know if it is the most concise method or not--but it works (and was the only method I found to work out of almost 10 methods I tried).

  1. First, when the main file needs to update the backend file, have it directly call the Zync - Check For Updates script from that backend file.
  2. Within each backend file, add a global number field; for example, I created an updateFlag field in my References table.
  3. Within each backend file, edit the Zync - Prep And Upload New File script, and in the section where it states # RUN PREP SCRIPT HERE add the steps
    • Set Field [References::updateFlag; 1]
    • Commit Records/Requests
  4. Optionally, add some steps to you Main Database's On Open script that you want to run after the backend file is updated and your main file is reopened. I am taking the user back to their original layout, and providing a confirmation message:
    • If [Get ( ScriptParameter ) = "backendUpdate"]
    • Go to Layout [layout that initiated the update, which is different that the default home screen]
    • Show Custom Dialog ["Update Successful"; "more text"]
    • End If
  5. Within each backend file, edit the script that runs when the file is first opened (and if you don't have one, create a script and assign it as a script trigger in the backend database's File->File Options->Script Triggers section.) Add these steps:
    • If [References::updateFlag = 1] //runs only after a new version is downloaded
    • Set Field [References::updateFlag; 0]
    • Commit Records/Requests
    • Open File ["Main Database"] //main database file was closed during the update process, need to open it back up ...
    • Perform Script ["Load Database" from file:"Main Database"; Parameter: "backendUpdate"] //... and optionally execute another script
    • Close File [Current File] //close the backend file, leaving us back in the main file
    • End If
  6. Edit GoZyncMobile's Check For Updates (File) script. About 25 lines up from the bottom of this script, before the line #Queue the zerver to inztall the new filez, add one line of code. This line, when placed here, is called if there is an update to your backend file, and closes your main file before GoZync's big Install Files script is called so that it isn't locking your backend file.
    • Close Window [Name: "Window Title of main database:] //maybe Close File would work better by being more robust?
Last edited by aewerdt on Mon Sep 23, 2013 11:18 am, edited 1 time in total.
SeedCode Staff
SeedCode Staff
Posts: 98
Joined: Mon Aug 13, 2012 7:43 am
PostPosted: Mon Sep 23, 2013 10:47 am
Great to hear you got it working. Thanks for posting your results here.

-Tanner

Return to GoZync

Who is online

Users browsing this forum: No registered users and 2 guests

cron
(855) SEEDCODE
[email protected]
Follow us: